简体   繁体   中英

WordPress File Upload always give PHP.ini error

Using the media_sideload_image method (save from URL) works well, but for a actual uploads using the WP function array(1) { ["error"]=> string(1) "s" } it always gives me the following message.

{ ["error"]=> string(212) "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." }

Which clearly means there was an error - why? I have looked at the PHP INI file and it doesn't appear to be that, is there another means of setting it?

PHP Code

$upload_photo = $_FILE['upload_photo'];
if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
 echo $upload_photo;
 $upload_overrides = array( 'test_form' => false );
 $movefile = wp_handle_upload( $upload_photo, $upload_overrides );
  if ( $movefile ) {
      echo "File is valid, and was successfully uploaded.\n";
      var_dump( $movefile);
  } else {
    echo "Possible file upload attack!\n";
  }

HTML Code

input type='text' value='Photo URL' id='upload_photo_url' name='upload_photo_url' onclick="clear_field('upload_photo_url');" />

PHP Settings (printed from phpinfo()) 在此处输入图片说明

  1. Create a file called phpinfo.php

  2. Save that file in your top level directory. Type yoursitename.com/phpinfo.php into the address bar and you will get a listing of all php information.

  3. Once you know where to find and save the file php.ini, either on your host server or local host, open that file and search for 'post_max_size' and 'upload_max_filesize'. Change both to the maximum file size that you need to upload and save.

  4. Upload the modified php.ini file to the directory you discovered with your phpinfo.php file. You will want to restart your localhost server and refresh the page. Uploading large files can now be accomplished.

我通过将以下代码添加到<form>标签中解决了这个问题。

enctype="multipart/form-data"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM