wp_handle_upload() works for me, but uploads files where it wants (uploads/year/month).
Question: Is there any way to tell it to upload files to a custom dir (uploads/mycustomdir)? Or is there some other function which could do this?
What I tried:
-
php’s move_uploaded_file() (wasn’t able to figure the target directory parameter – this is for a plugin and I need it to work for everyone regardless of their dir structure).
I pasted this code into my plugin’s core file. Nothing happened. But I see in the comments this seems to work for people.
PLEASE if you have an answer, give a complete one. I’m able to get $_FILES[‘myfile’]. What steps to take from there to make that file go to uploads/mycustomfolder?
You can work on the idea that Joost provided and use the
upload_dir
filter to temporarily set the upload path to somewhere else.And then in practice, it’s as easy as: