mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 06:38:00 +02:00
Related to issue #619. Attempt to detect and add file extension when it's missing and prior to media import.
This commit is contained in:
@@ -264,8 +264,13 @@ class e_file
|
|||||||
{
|
{
|
||||||
$finfo = $this->get_file_info($path."/".$file, ('file' != $this->finfo)); // -> 'all' & 'image'
|
$finfo = $this->get_file_info($path."/".$file, ('file' != $this->finfo)); // -> 'all' & 'image'
|
||||||
}
|
}
|
||||||
$finfo['path'] = $path."/"; // important: leave this slash here and update other file instead.
|
else
|
||||||
$finfo['fname'] = $file;
|
{
|
||||||
|
$finfo['path'] = $path.DIRECTORY_SEPARATOR; // important: leave this slash here and update other file instead.
|
||||||
|
$finfo['fname'] = $file;
|
||||||
|
}
|
||||||
|
// $finfo['path'] = $path.DIRECTORY_SEPARATOR; // important: leave this slash here and update other file instead.
|
||||||
|
// $finfo['fname'] = $file;
|
||||||
|
|
||||||
$ret[] = $finfo;
|
$ret[] = $finfo;
|
||||||
break;
|
break;
|
||||||
@@ -277,6 +282,24 @@ class e_file
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getFileExtension($mimeType)
|
||||||
|
{
|
||||||
|
$extensions = array(
|
||||||
|
'image/jpeg'=>'.jpg',
|
||||||
|
'image/png' => '.png',
|
||||||
|
'image/gif' => '.gif'
|
||||||
|
);
|
||||||
|
|
||||||
|
if(isset($extensions[$mimeType]))
|
||||||
|
{
|
||||||
|
return $extensions[$mimeType];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect file information
|
* Collect file information
|
||||||
* @param string $path_to_file
|
* @param string $path_to_file
|
||||||
@@ -291,16 +314,56 @@ class e_file
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$finfo['pathinfo'] = pathinfo($path_to_file);
|
||||||
|
|
||||||
|
if(class_exists('finfo')) // Best Mime detection method.
|
||||||
|
{
|
||||||
|
$fin = new finfo(FILEINFO_MIME);
|
||||||
|
list($mime, $other) = explode(";", $fin->file($path_to_file));
|
||||||
|
|
||||||
|
if(!empty($mime))
|
||||||
|
{
|
||||||
|
$finfo['mime'] = $mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-Fix Files without an extensions using known mime-type.
|
||||||
|
if(empty($finfo['pathinfo']['extension']) && !is_dir($path_to_file) && !empty($finfo['mime']))
|
||||||
|
{
|
||||||
|
if($ext = $this->getFileExtension($finfo['mime']))
|
||||||
|
{
|
||||||
|
$finfo['pathinfo']['extension'] = $ext;
|
||||||
|
|
||||||
|
|
||||||
|
$newFile = $path_to_file . $ext;
|
||||||
|
if(!file_exists($newFile))
|
||||||
|
{
|
||||||
|
if(rename($path_to_file,$newFile)===true)
|
||||||
|
{
|
||||||
|
$finfo['pathinfo'] = pathinfo($newFile);
|
||||||
|
$path_to_file = $newFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if($imgcheck && ($tmp = getimagesize($path_to_file)))
|
if($imgcheck && ($tmp = getimagesize($path_to_file)))
|
||||||
{
|
{
|
||||||
$finfo['img-width'] = $tmp[0];
|
$finfo['img-width'] = $tmp[0];
|
||||||
$finfo['img-height'] = $tmp[1];
|
$finfo['img-height'] = $tmp[1];
|
||||||
$finfo['mime'] = $tmp['mime'];
|
|
||||||
|
if(empty($finfo['mime']))
|
||||||
|
{
|
||||||
|
$finfo['mime'] = $tmp['mime'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp = stat($path_to_file);
|
|
||||||
|
|
||||||
|
$tmp = stat($path_to_file);
|
||||||
|
|
||||||
if($tmp)
|
if($tmp)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -309,9 +372,17 @@ class e_file
|
|||||||
}
|
}
|
||||||
|
|
||||||
// associative array elements: dirname, basename, extension, filename
|
// associative array elements: dirname, basename, extension, filename
|
||||||
$finfo['pathinfo'] = pathinfo($path_to_file);
|
|
||||||
|
|
||||||
$finfo['mime'] = vartrue($finfo['mime'],'application/'.$finfo['pathinfo']['extension']);
|
$finfo['fullpath'] = $path_to_file;
|
||||||
|
$finfo['fname'] = basename($path_to_file);
|
||||||
|
$finfo['path'] = dirname($path_to_file).DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
// $finfo['mime'] = vartrue($finfo['mime'],'application/'.$finfo['pathinfo']['extension']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $finfo;
|
return $finfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2809,11 +2809,11 @@ class e_form
|
|||||||
return $video;
|
return $video;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!preg_match("/[a-zA-z0-9_-\s\(\)]+\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)$/",$value))
|
if(!preg_match("/[a-zA-z0-9_-\s\(\)]+\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)$/",$value) && strpos($value,'.')!==false)
|
||||||
{
|
{
|
||||||
$icon = "{e_IMAGE}filemanager/zip_32.png";
|
$icon = "{e_IMAGE}filemanager/zip_32.png";
|
||||||
$src = $tp->replaceConstants(vartrue($parms['pre']).$icon, 'abs');
|
$src = $tp->replaceConstants(vartrue($parms['pre']).$icon, 'abs');
|
||||||
return '<img src="'.$src.'" alt="'.$value.'" class="e-thumb" title="'.$value.'" />';
|
// return '<img src="'.$src.'" alt="'.$value.'" class="e-thumb" title="'.$value.'" />';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vartrue($parms['thumb']))
|
if(vartrue($parms['thumb']))
|
||||||
|
@@ -959,13 +959,15 @@ class e_media
|
|||||||
|
|
||||||
$info = e107::getFile()->get_file_info($path,true);
|
$info = e107::getFile()->get_file_info($path,true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->log("File info for $path : ".print_r($info,true));
|
$this->log("File info for $path : ".print_r($info,true));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'media_type' => vartrue($info['mime']),
|
'media_type' => vartrue($info['mime']),
|
||||||
'media_datestamp' => time(),
|
'media_datestamp' => time(),
|
||||||
'media_url' => e107::getParser()->createConstants($path, 'rel'),
|
'media_url' => e107::getParser()->createConstants($info['fullpath'], 'rel'),
|
||||||
'media_size' => filesize($path),
|
'media_size' => filesize($info['fullpath']),
|
||||||
'media_author' => USERID,
|
'media_author' => USERID,
|
||||||
'media_usedby' => '',
|
'media_usedby' => '',
|
||||||
'media_tags' => '',
|
'media_tags' => '',
|
||||||
|
Reference in New Issue
Block a user