不上传文件时 SDK 解析 PHP 中的互联网服务器错误

Internet Server Error in SDK parse PHP when not uploading files

我有一个用于上传文件的代码。当我上传一些东西时它工作正常,但是当我没有上传任何东西时,消息 "Internal Server Error" 出现。

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();

应该是这样的。我没有测试它,但你可以看到这个想法

$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();

我终于可以让它工作了

 $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();