[英]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() 打印)
Create a file called phpinfo.php创建一个名为 phpinfo.php 的文件
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 信息的列表。
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.
将两者更改为您需要上传和保存的最大文件大小。
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.