Ticket #12278: 12278.diff
File 12278.diff, 5.0 KB (added by , 15 years ago) |
---|
-
wp-admin/includes/file.php
227 227 */ 228 228 function wp_handle_upload( &$file, $overrides = false, $time = null ) { 229 229 // The default error handler. 230 if ( ! function_exists( 'wp_handle_upload_error' ) ) {230 if ( ! function_exists( 'wp_handle_upload_error' ) ) { 231 231 function wp_handle_upload_error( &$file, $message ) { 232 232 return array( 'error'=>$message ); 233 233 } … … 262 262 // All tests are on by default. Most can be turned off by $override[{test_name}] = false; 263 263 $test_form = true; 264 264 $test_size = true; 265 $test_upload = true; 265 266 266 267 // If you override this, you must provide $ext and $type!!!! 267 268 $test_type = true; … … 273 274 274 275 // A correct form post will pass this test. 275 276 if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) 276 return $upload_error_handler($file, __( 'Invalid form submission.' ));277 return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' )); 277 278 278 279 // A successful upload will pass this test. It makes no sense to override this one. 279 280 if ( $file['error'] > 0 ) 280 return $upload_error_handler($file, $upload_error_strings[$file['error']] );281 return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] ); 281 282 282 283 // A non-empty file will pass this test. 283 if ( $test_size && !($file['size'] > 0 ) ) 284 return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' )); 284 if ( $test_size && !($file['size'] > 0 ) ) { 285 if ( is_multisite() ) 286 $error_msg = __( 'File is empty. Please upload something more substantial.' ); 287 else 288 $error_msg = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); 289 return call_user_func($upload_error_handler, $file, $error_msg); 290 } 285 291 286 292 // A properly uploaded file will pass this test. There should be no reason to override this one. 287 if ( ! @ is_uploaded_file( $file['tmp_name'] ) )288 return $upload_error_handler($file, __( 'Specified file failed upload test.' ));293 if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) ) 294 return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' )); 289 295 290 296 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 291 297 if ( $test_type ) { … … 294 300 extract( $wp_filetype ); 295 301 296 302 if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) 297 return $upload_error_handler($file, __( 'File type does not meet security guidelines. Try another.' ));303 return call_user_func($upload_error_handler, $file, __( 'File type does not meet security guidelines. Try another.' )); 298 304 299 305 if ( !$ext ) 300 306 $ext = ltrim(strrchr($file['name'], '.'), '.'); … … 307 313 308 314 // A writable uploads dir will pass this test. Again, there's no point overriding this one. 309 315 if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) ) 310 return $upload_error_handler( $file, $uploads['error'] );316 return call_user_func($upload_error_handler, $file, $uploads['error'] ); 311 317 312 318 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 313 319 314 320 // Move the file to the uploads dir 315 321 $new_file = $uploads['path'] . "/$filename"; 316 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) {322 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 317 323 return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 318 }319 324 320 325 // Set correct file permissions 321 326 $stat = stat( dirname( $new_file )); -
wp-admin/includes/media.php
177 177 * 178 178 * @since unknown 179 179 * 180 * @param unknown_type $file_id 181 * @param unknown_type $post_id 182 * @param unknown_type $post_data 183 * @return unknown 180 * @param string $file_id Index into the {@link $_FILES} array of the upload 181 * @param int $post_id The post ID the media is associated with 182 * @param array $post_data allows you to overwrite some of the attachment 183 * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior 184 * @return int the ID of the attachment 184 185 */ 185 function media_handle_upload($file_id, $post_id, $post_data = array()) { 186 $overrides = array('test_form'=>false); 186 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { 187 187 188 188 $time = current_time('mysql'); 189 189 if ( $post = get_post($post_id) ) {