1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

Auto fix extension parameter (allow disable auto-rename)

This commit is contained in:
SecretR
2014-08-19 14:03:42 +03:00
parent f9111fd5ca
commit b293dc71ef

View File

@@ -304,9 +304,10 @@ class e_file
* Collect file information * Collect file information
* @param string $path_to_file * @param string $path_to_file
* @param boolean $imgcheck * @param boolean $imgcheck
* @param boolean $auto_fix_ext
* @return array * @return array
*/ */
function get_file_info($path_to_file, $imgcheck = true) function get_file_info($path_to_file, $imgcheck = true, $auto_fix_ext = true)
{ {
$finfo = array(); $finfo = array();
@@ -329,25 +330,28 @@ class e_file
} }
// Auto-Fix Files without an extensions using known mime-type. if($auto_fix_ext)
if(empty($finfo['pathinfo']['extension']) && !is_dir($path_to_file) && !empty($finfo['mime'])) {
{ // Auto-Fix Files without an extensions using known mime-type.
if($ext = $this->getFileExtension($finfo['mime'])) if(empty($finfo['pathinfo']['extension']) && !is_dir($path_to_file) && !empty($finfo['mime']))
{ {
$finfo['pathinfo']['extension'] = $ext; if($ext = $this->getFileExtension($finfo['mime']))
{
$finfo['pathinfo']['extension'] = $ext;
$newFile = $path_to_file . $ext; $newFile = $path_to_file . $ext;
if(!file_exists($newFile)) if(!file_exists($newFile))
{ {
if(rename($path_to_file,$newFile)===true) if(rename($path_to_file,$newFile)===true)
{ {
$finfo['pathinfo'] = pathinfo($newFile); $finfo['pathinfo'] = pathinfo($newFile);
$path_to_file = $newFile; $path_to_file = $newFile;
} }
} }
} }
} }
}
if($imgcheck && ($tmp = getimagesize($path_to_file))) if($imgcheck && ($tmp = getimagesize($path_to_file)))