- // Move the file to the uploads dir
- if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
- wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
+ if ( isset( $file['error'] ) )
+ wp_die( $file['error'] );
+
+ $this->filename = $_FILES[$form]['name'];
+ $this->package = $file['file'];
+
+ // Construct the object array
+ $object = array(
+ 'post_title' => $this->filename,
+ 'post_content' => $file['url'],
+ 'post_mime_type' => $file['type'],
+ 'guid' => $file['url'],
+ 'context' => 'upgrader',
+ 'post_status' => 'private'
+ );
+
+ // Save the data
+ $this->id = wp_insert_attachment( $object, $file['file'] );
+
+ // schedule a cleanup for 2 hours from now in case of failed install
+ wp_schedule_single_event( time() + 7200, 'upgrader_scheduled_cleanup', array( $this->id ) );
+
+ } elseif ( is_numeric( $_GET[$urlholder] ) ) {
+ // Numeric Package = previously uploaded file, see above.
+ $this->id = (int) $_GET[$urlholder];
+ $attachment = get_post( $this->id );
+ if ( empty($attachment) )
+ wp_die(__('Please select a file'));
+
+ $this->filename = $attachment->post_title;
+ $this->package = get_attached_file( $attachment->ID );