Catch upload errors #393
This commit is contained in:
parent
bfedfa3f94
commit
eef971e3eb
@ -42,6 +42,7 @@ class Import extends Module {
|
||||
$nameFile[0]['tmp_name'] = $path;
|
||||
$nameFile[0]['error'] = 0;
|
||||
$nameFile[0]['size'] = $size;
|
||||
$nameFile[0]['error'] = UPLOAD_ERR_OK;
|
||||
|
||||
if (!$photo->add($nameFile, $albumID, $description, $tags, true)) return false;
|
||||
return true;
|
||||
|
@ -88,6 +88,41 @@ class Photo extends Module {
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
# Check if file exceeds the upload_max_filesize directive
|
||||
if ($file['error']===UPLOAD_ERR_INI_SIZE) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, 'The uploaded file exceeds the upload_max_filesize directive in php.ini');
|
||||
if ($returnOnError===true) return false;
|
||||
exit('Error: The uploaded file exceeds the upload_max_filesize directive in php.ini!');
|
||||
}
|
||||
|
||||
# Check if file was only partially uploaded
|
||||
if ($file['error']===UPLOAD_ERR_PARTIAL) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, 'The uploaded file was only partially uploaded');
|
||||
if ($returnOnError===true) return false;
|
||||
exit('Error: The uploaded file was only partially uploaded!');
|
||||
}
|
||||
|
||||
# Check if writing file to disk failed
|
||||
if ($file['error']===UPLOAD_ERR_CANT_WRITE) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, 'Failed to write photo to disk');
|
||||
if ($returnOnError===true) return false;
|
||||
exit('Error: Failed to write photo to disk!');
|
||||
}
|
||||
|
||||
# Check if a extension stopped the file upload
|
||||
if ($file['error']===UPLOAD_ERR_EXTENSION) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, 'A PHP extension stopped the file upload');
|
||||
if ($returnOnError===true) return false;
|
||||
exit('Error: A PHP extension stopped the file upload!');
|
||||
}
|
||||
|
||||
# Check if the upload was successful
|
||||
if ($file['error']!==UPLOAD_ERR_OK) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, 'Upload contains an error (' . $file['error'] . ')');
|
||||
if ($returnOnError===true) return false;
|
||||
exit('Error: Upload failed!');
|
||||
}
|
||||
|
||||
# Verify extension
|
||||
$extension = getExtension($file['name']);
|
||||
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
|
||||
|
Loading…
Reference in New Issue
Block a user