Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
- $index = null, $content_range = null) {
- $file = new stdClass();
- $file->name = $this->get_file_name($name, $type, $index, $content_range);
- $file->size = $this->fix_integer_overflow(intval($size));
- $file->type = $type;
- if ($this->validate($uploaded_file, $file, $error, $index)) {
- $this->handle_form_data($file, $index);
- $upload_dir = $this->get_upload_path();
- if (!is_dir($upload_dir)) {
- mkdir($upload_dir, $this->options['mkdir_mode'], true);
- }
- $file_path = $this->get_upload_path($file->name);
- $append_file = $content_range && is_file($file_path) &&
- $file->size > $this->get_file_size($file_path);
- if ($uploaded_file && is_uploaded_file($uploaded_file)) {
- // multipart/formdata uploads (POST method uploads)
- if ($append_file) {
- file_put_contents(
- $file_path,
- fopen($uploaded_file, 'r'),
- FILE_APPEND
- );
- } else {
- move_uploaded_file($uploaded_file, $file_path);
- }
- } else {
- // Non-multipart uploads (PUT method support)
- file_put_contents(
- $file_path,
- fopen('php://input', 'r'),
- $append_file ? FILE_APPEND : 0
- );
- }
- $file_size = $this->get_file_size($file_path, $append_file);
- if ($file_size === $file->size) {
- $file->url = $this->get_download_url($file->name);
- list($img_width, $img_height) = @getimagesize($file_path);
- if (is_int($img_width) &&
- preg_match($this->options['inline_file_types'], $file->name)) {
- $this->handle_image_file($file_path, $file);
- }
- } else {
- $file->size = $file_size;
- if (!$content_range && $this->options['discard_aborted_uploads']) {
- unlink($file_path);
- $file->error = 'abort';
- }
- }
- $this->set_additional_file_properties($file);
- }
- return $file;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement