Jump to content

Allow file upload extension


Recommended Posts

Hy. How to allow customers to upload pdf file? I changed this code in images.inc.php but is not working..

 

function isPicture($file, $types = NULL)
{
// Filter on file extension
$authorized_extensions = array('gif', 'jpg', 'jpeg', 'jpe', 'png', 'exe', 'pdf');
$name_explode = explode('.', $file['name']);
if (count($name_explode) >= 2)
{
 $current_extension = strtolower($name_explode[count($name_explode)-1]);
 if (!in_array($current_extension, $authorized_extensions))
  return false;
}
else
 return true;
/* Detect mime content type */
$mimeType = false;
if (!$types)
 $types = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'application/x-pdf');
/* Try 4 different methods to determine the mime type */
if (function_exists('finfo_open'))
{
 $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
 $finfo = finfo_open($const);
  $mimeType = finfo_file($finfo, $file['tmp_name']);
 finfo_close($finfo);
}
elseif (function_exists('mime_content_type'))
 $mimeType = mime_content_type($file['tmp_name']);
elseif (function_exists('exec'))
{
 $mimeType = trim(exec('file -b --mime-type '.escapeshellarg($file['tmp_name'])));
 if (!$mimeType)
  $mimeType = trim(exec('file --mime '.escapeshellarg($file['tmp_name'])));
 if (!$mimeType)
  $mimeType = trim(exec('file -bi '.escapeshellarg($file['tmp_name'])));
}
if (empty($mimeType) OR $mimeType == 'regular file' OR $mimeType == 'text/plain')
 $mimeType = $file['type'];
/* For each allowed MIME type, we are looking for it inside the current MIME type */
foreach ($types AS $type)
 if (strstr($mimeType, $type))
  return true;
return false;
}

Edited by mirceabondar (see edit history)
Link to comment
Share on other sites

  • 9 months later...
  • 1 year later...
×
×
  • Create New...