I am using a front end script to upload images , all works fine but recently i noticed the uploaded images are not saved in proper directory. My settings are to Organize my uploads into month- and year-based folders. my folders are 2011->03,04,05 (march , April , may). The problem is that if i upload a file today it saves in folder 03(March). If i use wp_handle_upload then the image is saved in proper folder 05 (May) , but then the image is not shown in media library and the different sizes are not made.
Code i am using is
$image = media_handle_upload('async-upload', '');
Look into the first lines of this function:
The time is taken from the post date. You could bypass
media_handle_upload()
and usewp_handle_upload()
directly.Update
I donât have the time to write a fully working standalone example, but here is an excerpt from my theme options class. It handles uploads, generates different images sizes and an attachment id. It is called by the general save function and handles multiple uploaded files in one rush.
Some notes:
is_allowed_mime()
checks for MIME types set in$fields
which are set in my controller. The MIME type for a favicon for example is eitherimage/x-icon
orimage/vnd.microsoft.icon
.get_media_name()
may use a predefined name for the attachment (e.g. logo).$attach_id
and use it in a post meta field or something similar.