2015-08-18 48 views
2

我有一個代碼,我正在使用爲了上傳文件。它在我上傳某些內容時正常工作,但是當我沒有上傳任何內容時,將顯示消息「內部服務器錯誤」。Internet服務器錯誤SDK解析PHP不上傳文件時

if (isset($_FILES['image'])) { 
     if ($_FILES['image']['size'] < 600000) { 
      // save file to Parse 
      $file = ParseFile::createFromData( 
         file_get_contents($_FILES['image']['tmp_name']), 
         $_FILES['image']['name'] ); 
      $file->save(); 
     } else { 
      echo "El archivo no se adjuntó porque rebasa el tamaño máximo permitido"; 
     } 
    } else { 
     $file = ""; 
    } 

//The error remains if i take out this code which saves the image on the Parse database. 
// So the problem is in the code above. 

$report = new ParseObject("Report"); 
if (isset($file)) { $report->set("ImageFile", $file); } 
$report->save(); 
+0

喜嘗試第一行,如果(計數($ _ FILES)> 0){... }並在使用file_get_contents($ _FILES ['image'] ['tmp_name'])之前,你需要檢查文件是否存在 – volkinc

+0

我仍然有同樣的問題 –

+0

什麼行?錯誤應該給你錯誤行 – volkinc

回答

0

最後,我可以讓它工作

$isFileExists = (file_exists ($_FILES['image']['tmp_name'])) && ($_FILES['image']['error'] != 4); 
if (isset($_FILES['image']) && $isFileExists) { 
    $isGoodSize = ($_FILES['image']['size'] < 600000) && ($_FILES['image']['size'] > 0); 

     if ($isFileExists && $isGoodSize) { 

      $file = ParseFile::createFromData( 
         file_get_contents($_FILES['image']['tmp_name']), 
         $_FILES['image']['name'] ); 
      $file->save(); 
     } else { 
      echo "No adjuntaste alguna imagen, o no se subió porque rebasa el tamaño máximo permitido"; 
     } 
    } 
if (isset($file)) { $report->set("ImageFile", $file); } 
    $report->save(); 
0

它應該是這樣的。我沒有測試它,但你可以看到這個想法

$file = ""; 
if (!empty($_FILES['image']['name'])) { 
    $isFileExists = file_exists ($_FILES['image']['tmp_name']); 
    $isGoodSize = ($_FILES['image']['size'] < 600000) && ($_FILES['image']['size'] > 0); 

     if ($isFileExists && $isGoodSize) { 

      $file = ParseFile::createFromData( 
         file_get_contents($_FILES['image']['tmp_name']), 
         $_FILES['image']['name'] ); 
      $file->save(); 
     } else { 
      echo "El archivo no se adjuntó porque rebasa el tamaño máximo permitido"; 
     } 
    } 

$report = new ParseObject("Report"); 
if (isset($file)) { $report->set("ImageFile", $file); } 
$report->save(); 
+0

不,它沒有工作:( –

+0

地方退出()代碼開始之前,看看你是否仍然有一個錯誤 – volkinc

+0

錯誤消失。錯誤是在代碼中,問題是我不知道這是錯誤 –

相關問題