- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-file-upload-upgrader.php
r41289 r42343 53 53 public function __construct( $form, $urlholder ) { 54 54 55 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) 56 wp_die(__('Please select a file')); 55 if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) { 56 wp_die( __( 'Please select a file' ) ); 57 } 57 58 58 59 //Handle a newly uploaded file, Else assume it's already been uploaded 59 if ( ! empty($_FILES) ) { 60 $overrides = array( 'test_form' => false, 'test_type' => false ); 61 $file = wp_handle_upload( $_FILES[$form], $overrides ); 60 if ( ! empty( $_FILES ) ) { 61 $overrides = array( 62 'test_form' => false, 63 'test_type' => false, 64 ); 65 $file = wp_handle_upload( $_FILES[ $form ], $overrides ); 62 66 63 if ( isset( $file['error'] ) ) 67 if ( isset( $file['error'] ) ) { 64 68 wp_die( $file['error'] ); 69 } 65 70 66 $this->filename = $_FILES[ $form]['name'];67 $this->package = $file['file'];71 $this->filename = $_FILES[ $form ]['name']; 72 $this->package = $file['file']; 68 73 69 74 // Construct the object array 70 75 $object = array( 71 'post_title' => $this->filename,72 'post_content' => $file['url'],76 'post_title' => $this->filename, 77 'post_content' => $file['url'], 73 78 'post_mime_type' => $file['type'], 74 'guid' => $file['url'],75 'context' => 'upgrader',76 'post_status' => 'private'79 'guid' => $file['url'], 80 'context' => 'upgrader', 81 'post_status' => 'private', 77 82 ); 78 83 … … 83 88 wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) ); 84 89 85 } elseif ( is_numeric( $_GET[ $urlholder] ) ) {90 } elseif ( is_numeric( $_GET[ $urlholder ] ) ) { 86 91 // Numeric Package = previously uploaded file, see above. 87 $this->id = (int) $_GET[$urlholder];92 $this->id = (int) $_GET[ $urlholder ]; 88 93 $attachment = get_post( $this->id ); 89 if ( empty($attachment) ) 90 wp_die(__('Please select a file')); 94 if ( empty( $attachment ) ) { 95 wp_die( __( 'Please select a file' ) ); 96 } 91 97 92 98 $this->filename = $attachment->post_title; 93 $this->package = get_attached_file( $attachment->ID );99 $this->package = get_attached_file( $attachment->ID ); 94 100 } else { 95 101 // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler. 96 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 102 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) { 97 103 wp_die( $uploads['error'] ); 104 } 98 105 99 106 $this->filename = sanitize_file_name( $_GET[ $urlholder ] ); 100 $this->package = $uploads['basedir'] . '/' . $this->filename;107 $this->package = $uploads['basedir'] . '/' . $this->filename; 101 108 102 109 if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) { … … 114 121 */ 115 122 public function cleanup() { 116 if ( $this->id ) 123 if ( $this->id ) { 117 124 wp_delete_attachment( $this->id ); 118 125 119 elseif ( file_exists( $this->package ) )126 } elseif ( file_exists( $this->package ) ) { 120 127 return @unlink( $this->package ); 128 } 121 129 122 130 return true;
Note: See TracChangeset
for help on using the changeset viewer.