最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Specified file failed upload test. Error When Uploading Image From Front-end

programmeradmin1浏览0评论

This is my code:

$file_return = wp_handle_upload($_FILES['my-photo'], array('test_form' => FALSE));

if(isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
    echo "And so it DIED...";
    print_r($file_return);
    die;
}

Why is not uploading to the uploads dir and why is it throwing a "Specified file failed upload test."?

This is my code:

$file_return = wp_handle_upload($_FILES['my-photo'], array('test_form' => FALSE));

if(isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
    echo "And so it DIED...";
    print_r($file_return);
    die;
}

Why is not uploading to the uploads dir and why is it throwing a "Specified file failed upload test."?

Share Improve this question asked May 22, 2013 at 7:40 Pi LoverPi Lover 761 gold badge1 silver badge8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 1

Check the documentation wp_handle_upload
You need to include the file.php before calling wp_handle_upload

require_once( ABSPATH . 'wp-admin/includes/file.php' )

Check may be same filename already uploaded. I was getting same error because of same filename.

The wp_handle_upload tries to read the file data from the lowest dimension of the given array. Like: $file['tmp_name']. So, if the given info is on a, i.e., secondary layer of the array (like $file['my-photo']['image']), it will not find the expected index, and fire a notice in your log, like this:

PHP Notice: Undefined index: tmp_name

And fail the upload test. Check your error log for warnings. Also, check the method's source for your error message, this might help you a lot: https://developer.wordpress/reference/functions/_wp_handle_upload/#source (line #792).

发布评论

评论列表(0)

  1. 暂无评论