WordPress的上传媒体

时间:2018-08-14 20:09:32

标签: wordpress plugins upload media

我想使用功能media_handle_upload将媒体上传到自定义插件中的wordpress。

在将文件传递给函数之前,对象看起来像这样:

constructorArray ( [name] => limit (2).jpg [type] => image/jpeg [tmp_name] => /tmp/phpxBWMPN [error] => 0 [size] => 43734 )

致电media_handle_upload

$movefile = media_handle_upload($file, 0);

我得到了这个错误对象。

WP_Error Object ( [errors] => Array ( [upload_error] => Array ( [0] => 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_data] => Array ( ) )

我正在网上搜索解决方案。我得到建议,我必须更改php.ini中的帖子和上传大小。该文件是Wordpress的一部分还是我的cpanel的一部分?

还有其他解决方案可以使该程序运行吗?

1 个答案:

答案 0 :(得分:0)

获得分辨率:

请勿将这样的文件传递给函数:

media_handle_upload($_FILES('myFileUpload'), 0);

分辨率只需将其作为字符串传递:)

media_handle_upload('myFileUpload', 0);