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?
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
to
Because the syntax of
media_handle_upload()
is:The
$post_id
cannot be before$file_id
.