1

I pasted my codes HERE in Pastebin.

Thing is that, I have posts, where the post thumbnail is the first image and the custom fields are used to store the other 3 images of the post. The form fields are working, because I could change/edit the fields, but the problem is with the media uploader. By the time I'm uploading an image it's not taking the image, but storing an error message to the database:

O:8:"WP_Error":2:{s:6:"errors";a:1:{s:12:"upload_error";a:1:{i:0;s: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.";}}s:10:"error_data";a:0:{}}

But I used advanced custom fields plugin, and that's working properly with the same image, and the WordPress default media uploader is working too with the same image file. So, I think there is no restriction like max_filesize in my localhost. And also, I tried this on the server, and it's till working the same.

I failed to upload an image.

What's the problem in my code?

1

Yes, got the problem. A minute off-track, and it's wrong! :p

On line 80, 87, 93 and 99 in Pastebin Codes, the syntax of media_handle_upload() was wrong.

It should be substituted from

media_handle_upload($postid,'product_image_1');

to

media_handle_upload('product_image_1', $postid);

Because the syntax of media_handle_upload() is:

media_handle_upload( $file_id, $post_id, $post_data, $overrides );

The $post_id cannot be before $file_id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.