Make WordPress Core


Ignore:
Timestamp:
02/22/2010 04:54:51 PM (16 years ago)
Author:
ryan
Message:

Pass overrides. Allow ref array calling. Props tychay. fixes #12278

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r13223 r13290  
    228228function wp_handle_upload( &$file, $overrides = false, $time = null ) {
    229229    // The default error handler.
    230     if (! function_exists( 'wp_handle_upload_error' ) ) {
     230    if ( ! function_exists( 'wp_handle_upload_error' ) ) {
    231231        function wp_handle_upload_error( &$file, $message ) {
    232232            return array( 'error'=>$message );
     
    263263    $test_form = true;
    264264    $test_size = true;
     265    $test_upload = true;
    265266
    266267    // If you override this, you must provide $ext and $type!!!!
     
    274275    // A correct form post will pass this test.
    275276    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.' ));
    277278
    278279    // A successful upload will pass this test. It makes no sense to override this one.
    279280    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']] );
    281282
    282283    // 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    }
    285291
    286292    // 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.' ));
    289295
    290296    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
     
    295301
    296302        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.' ));
    298304
    299305        if ( !$ext )
     
    308314    // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    309315    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'] );
    311317
    312318    $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
     
    314320    // Move the file to the uploads dir
    315321    $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 ) )
    317323        return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
    318     }
    319324
    320325    // Set correct file permissions
Note: See TracChangeset for help on using the changeset viewer.