简体   繁体   English

WordPress 文件上传总是出现 PHP.ini 错误

[英]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.使用 media_sideload_image 方法(从 URL 保存)效果很好,但对于使用 WP 函数array(1) { ["error"]=> string(1) "s" }的实际上传,它总是给我以下消息。

{ ["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." { ["error"]=> string(212) "文件为空。请上传更多内容。此错误也可能是由于在 php.ini 中禁用上传或 post_max_size 在 php 中被定义为小于 upload_max_filesize 引起的。 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 INI 文件,但似乎不是这样,还有其他设置方法吗?

PHP Code PHP代码

$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 HTML代码

input type='text' value='Photo URL' id='upload_photo_url' name='upload_photo_url' onclick="clear_field('upload_photo_url');" 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()) PHP 设置(从 phpinfo() 打印)在此处输入图片说明

  1. Create a file called phpinfo.php创建一个名为 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.在地址栏中键入 yoursitename.com/phpinfo.php,您将获得所有 php 信息的列表。

  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'.一旦您知道在哪里可以找到并保存文件 php.ini,无论是在您的主机服务器还是本地主机上,打开该文件并搜索“post_max_size”和“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.将修改后的 php.ini 文件上传到您使用 phpinfo.php 文件发现的目录。 You will want to restart your localhost server and refresh the page.您需要重新启动本地主机服务器并刷新页面。 Uploading large files can now be accomplished.现在可以完成上传大文件。

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

enctype="multipart/form-data"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress忽略php.ini上传最大文件大小 - WordPress ignoring php.ini upload max file size Wordpress php.ini文件将upload_max_filesize设置为大约2MB上传 - Wordpress php.ini file to set upload_max_filesize to get around 2MB upload 增加 Google Cloud Platform Kubernetes Wordpress Click-to-Deploy 上的 PHP.ini 文件上传限制 - Increase PHP.ini file upload limit on Google Cloud Platform Kubernetes Wordpress Click-to-Deploy 在Wordpress主题内使用.htaccess定义php.ini路径,以更改upload_file_size? - Define php.ini path with .htaccess inside a Wordpress theme to change upload_file_size? 没有php.ini文件 - No php.ini file Wordpress PHP.INI 噩梦 - Wordpress PHP.INI nightmare 损坏的 php.ini (wordpress) - Corrupted php.ini (wordpress) 文件上传错误-&gt;尝试将php.ini文件访问OPENSHIFT免费应用程序,并获得“拒绝权限”响应 - File UPLOAD error -> Trying access the php.ini file into the OPENSHIFT free application and get Permission Denied response 上传插件时上传文件超出php.ini错误中的upload_max_filesize指令 - The uploaded file exceeds the upload_max_filesize directive in php.ini error while uploading plugin Wordpres错误,CentOs服务器:上传的文件超出了php.ini中的upload_max_filesize指令 - Wordpres Error, CentOs server: The uploaded file exceeds the upload_max_filesize directive in php.ini
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM