Beispiel #1
0
 /**
  * Moves the uploaded file from its temporary location to the server.
  *
  * This method will also create web and thumbnail sizes of the media.
  *
  * @param array $file The uploaded file from the $_FILES array.
  * @param string $filename The filename to be moved to.
  * @param string $extension The extension of the moved file.
  * @param string &$histograms Will be given a serialized histogram object.
  * @param bool $allow_dupes Whether duplicates should be allowed.
  * @return array A status array, where the 'status' index is the status code of the operation, and the 'response' index is a string describing the status.
  */
 private static function move_to_server($file, $filename, $extension, &$histograms, $allow_dupes)
 {
     $move_to = UPLOADS_DIR . "/{$filename}.{$extension}";
     // If the upload fails, return an error message
     if (!move_uploaded_file($file['tmp_name'], $move_to)) {
         return array('status' => STATUS_UPLOAD_ERROR, 'response' => "Couldn't move the file to the server.");
     }
     self::create_image_sizes($filename, $extension);
     // Create a serialized histogram for the database
     // Using the web source because it's smaller than the full size
     $web_src = UPLOADS_DIR . "/{$filename}" . WEB_SRC_SUFFIX . ".{$extension}";
     $thumb_src = UPLOADS_DIR . "/{$filename}" . THUMB_SRC_SUFFIX . ".{$extension}";
     $histograms = Histogram::create_from($web_src);
     // Compare histogram against exisiting images to prevent duplicates
     $histogram = new Histogram($histograms);
     $similar_id = $histogram->compare_against_database();
     // If a similar image was found, return a status
     if ($similar_id !== null && !$allow_dupes) {
         // Delete the uploaded files from the server
         unlink(UPLOADS_DIR . "/{$filename}.{$extension}");
         unlink($web_src);
         unlink($thumb_src);
         return array('status' => STATUS_SIMILAR_EXISTS, 'response' => $similar_id);
     }
     return array('status' => STATUS_OK, 'response' => 'File successfully moved to server.');
 }