Advertisement
Guest User

Untitled

a guest
Aug 28th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1.     protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
  2.             $index = null, $content_range = null) {
  3.         $file = new stdClass();
  4.         $file->name = $this->get_file_name($name, $type, $index, $content_range);
  5.         $file->size = $this->fix_integer_overflow(intval($size));
  6.         $file->type = $type;
  7.         if ($this->validate($uploaded_file, $file, $error, $index)) {
  8.             $this->handle_form_data($file, $index);
  9.             $upload_dir = $this->get_upload_path();
  10.             if (!is_dir($upload_dir)) {
  11.                 mkdir($upload_dir, $this->options['mkdir_mode'], true);
  12.             }
  13.             $file_path = $this->get_upload_path($file->name);
  14.             $append_file = $content_range && is_file($file_path) &&
  15.                 $file->size > $this->get_file_size($file_path);
  16.             if ($uploaded_file && is_uploaded_file($uploaded_file)) {
  17.                 // multipart/formdata uploads (POST method uploads)
  18.                 if ($append_file) {
  19.                     file_put_contents(
  20.                         $file_path,
  21.                         fopen($uploaded_file, 'r'),
  22.                         FILE_APPEND
  23.                     );
  24.                 } else {
  25.                     move_uploaded_file($uploaded_file, $file_path);
  26.                 }
  27.             } else {
  28.                 // Non-multipart uploads (PUT method support)
  29.                 file_put_contents(
  30.                     $file_path,
  31.                     fopen('php://input', 'r'),
  32.                     $append_file ? FILE_APPEND : 0
  33.                 );
  34.             }
  35.             $file_size = $this->get_file_size($file_path, $append_file);
  36.             if ($file_size === $file->size) {
  37.                 $file->url = $this->get_download_url($file->name);
  38.                 list($img_width, $img_height) = @getimagesize($file_path);
  39.                 if (is_int($img_width) &&
  40.                         preg_match($this->options['inline_file_types'], $file->name)) {
  41.                     $this->handle_image_file($file_path, $file);
  42.                 }
  43.             } else {
  44.                 $file->size = $file_size;
  45.                 if (!$content_range && $this->options['discard_aborted_uploads']) {
  46.                     unlink($file_path);
  47.                     $file->error = 'abort';
  48.                 }
  49.             }
  50.             $this->set_additional_file_properties($file);
  51.         }
  52.         return $file;
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement