2015-08-18 47 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

错误消失。错误是在代码中,问题是我不知道这是错误 –

相关问题