2017-09-13 25 views
1

最近我一直在运行响应式文件管理器,无论是在本地机器上还是在托管服务器上,尽管代码相同,它们仍然收到不同的问题。这些问题都与文件上传有关 - 目前测试的文件都只有JPEG文件,其中大于2 MB的JPEG文件无法上传。响应式文件管理器上传问题

共享问题:

对于本地机器&托管服务器,如果上传的图片超过8MB,然后我收到以下错误信息:

The uploaded file exceeeds the max size allowed.

本地机器的问题:

仅针对本地机器,如果上传的图像很棒呃超过2MB但比8MB少,我收到以下错误信息:

Warning: mime_content_type(): Empty filename or path in C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php on line 92.

其中线92指的是这个特定行一组if语句中:

if (! empty($_FILES) || isset($_POST['url'])) 
{ 
    if(isset($_POST['url'])){ 
     $temp = tempnam('/tmp','RF'); 
     $handle = fopen($temp, "w"); 
     fwrite($handle, file_get_contents($_POST['url'])); 
     fclose($handle); 
     $_FILES['file']= array(
      'name' => basename($_POST['url']), 
      'tmp_name' => $temp, 
      'size' => filesize($temp), 
      'type' => explode(".", strtolower($temp)) 
     ); 
    } 

    $info = pathinfo($_FILES['file']['name']); 
    $mime_type = $_FILES['file']['type']; 
    if (function_exists('mime_content_type')){ 
     $mime_type = mime_content_type($_FILES['file']['tmp_name']); //line 92 
    } 
} 

我也收到此错误还有:

File extension is not allowed. (@C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php#260) 

这是指如果此集合声明:

if (! empty($_FILES) || isset($_POST['url'])) 
{ 
    else // file ext. is not in the allowed list 
    { 
     response(trans("Error_extension").AddErrorLocation(), 406)->send(); //line 260 

     exit(); 
    } 
} 

服务器问题:

Not enough Memory 
(@/home/site/public_html/webroot/3rdparty/responsive file manager/filemanager.upload.php#241) 

这是指如果此集合声明:

if (! empty($_FILES) || isset($_POST['url'])) 
{ 
    if (in_array(fix_strtolower($extension), $ext)) 
    { 
     if ($is_img) 
     { 
      $memory_error = FALSE; 
      if ($extension != 'svg' && !create_img($targetFile, $targetFileThumb, 122, 91)) 
      { 
       $memory_error = TRUE; 
      } 
      // not enough memory 
      if ($memory_error) 
      { 
       unlink($targetFile); 
       response(trans("Not enought Memory").AddErrorLocation(), 406)->send(); //line 241 
       exit(); 
      } 
     } 
    } 
} 

在服务器上,这两个问题都通过这个单一的错误取代

到目前为止的尝试次数:

我看以下内容:

  • 与本地机器上的文件扩展名的问题,我查了允许的文件扩展名的config.php文件,但JPEG两种格式都已经在那里:

'ext_img' => array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg'), //Images

与此同时,在包括\ mime_type_lib.php,JPEG两种格式已经在那里:

$mime_types = array(
    'jpeg' => 'image/jpeg', 
    'jpg'  => 'image/jpeg', 
) 
  • 在我的本地机器上,我将upload_max_filesize增加到了128M。同时在服务器上,我使用cPanel的PHP设置来做同样的事情。另外在配置中。PHP文件,我改变了MaxSizeUpload设置如下符合上述变化:

'MaxSizeUpload' => 128,

  • 我也对证的config.php文件的最新版本和upload.php的,看看我的版本已经过时了,但事实并非如此。
+0

的tempnam'( '/ TMP', 'RF')'生成像模板文件:'因此/ TMP/RF123.tmp'起作用'mime_content_type'不能确定MIME类型...对于服务器问题,我们不知道哪些功能fillup变量'$ memory_error' – Kazz

+0

'mime_content_type($ _ FILES ['file'] ['tmp_name']);'是错误的,因为'tmp_name'是没有扩展名的文件如果我改变'mime_content_type($ _ FILES ['file'] ['tmp_name']),那么你应该检查'name'而不是'explode(“。”,strtolower($ temp))''返回一个不是字符串的数组 – Kazz

+0

;'''mime_content_type($ _ FILES ['file'] ['name']);',我得到这个错误:'mime_content_t ype(testimage.JPG):无法打开流:在第92行中的C:\ xampp \ htdocs \ project \ webroot \ 3rdparty \ responsive file manager \ filemanager \ upload.php中没有这样的文件或目录,而文件扩展名是不允许错误仍然存​​在。我刚刚添加到我的问题帖子,其中'$ memory_error'来自服务器问题。 – mistaq

回答

0

尝试这种情况:

if (! empty($_FILES) || isset($_POST['url'])) 
{ 
    if(isset($_POST['url'])){ 
     if(FALSE === ($temp = tempnam('/tmp','RF'))){ 
      response(trans("Failed to create temporary file").AddErrorLocation(), 406)->send(); 
      exit(); 
     } 
     $handle = fopen($temp, "w"); 
     fwrite($handle, file_get_contents($_POST['url'])); 
     fclose($handle); 
     $explUrl = explode(".", basename($_POST['url'])); 
     $suffix = array_pop($explUrl); 
     $_FILES['file']= array(
      'name' => basename($_POST['url']), 
      'tmp_name' => $temp, 
      'size' => filesize($temp), 
      // type should be mime-type not file suffix 
      'type' => $suffix, 
      'error' => UPLOAD_ERR_OK 
     ); 
    } 

    if($_FILES['file']['error'] !== UPLOAD_ERR_OK){ 
     response(trans("Error upload code: ".$_FILES['file']['error']).AddErrorLocation(), 406)->send(); 
     // error code list: http://php.net/manual/en/features.file-upload.errors.php 
     exit(); 
    } 

    if(empty($_FILES['file']['tmp_name'])){ 
     response(trans("Error upload").AddErrorLocation(), 406)->send(); 
     exit(); 
    } 

    $info = pathinfo($_FILES['file']['name']); 
    $mime_type = $_FILES['file']['type']; 
    if (function_exists('mime_content_type')){ 
     $mime_type = mime_content_type($_FILES['file']['tmp_name']); 
    } 
} 
+0

收到此错误:'错误上传代码:1(@C:\ xampp \ htdocs \ project \ webroot \ 3rdparty \ responsive file manager \ filemanager \ upload.php#114)',其中第114行指向'response(trans “错误上传代码:”。$ _ FILES ['file'] ['error'])。AddErrorLocation(),406) - > send();'。根据您的意见,我还将'type''更改为'$ mime_type',但这并没有改变错误。 – mistaq

+0

from http://php.net/manual/en/features.file-upload.errors.php值:1;上传的文件超出了php.ini中的upload_max_filesize指令。 – Kazz

+0

当您更改'upload_max_filesize'时,您必须重新启动服务器 – Kazz