I have a code i'm using in order to upload files. It works right when I upload something, but when I'm not upload nothing, the message "Internal Server Error" appears.
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();
Finally I could make it work
$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();