2017-09-13 74 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