I want to get the full local filename of an uploaded image so that I can copy it to a new directory and process it with my own image processing scripts. Which hooks/actions should I look into to achieve this?
Thanks
I want to get the full local filename of an uploaded image so that I can copy it to a new directory and process it with my own image processing scripts. Which hooks/actions should I look into to achieve this?
Thanks
You must be logged in to post a comment.
The
handle_upload
hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve:Edit: If you need the attachment ID as well, it might be better hooking in at a higher level, such as add / edit attachment:
in which case the variable sent in is the attachment_id, from which you can derive the rest using something like:
If you want the filename, and not just the path relative to the root of the file, you must add this line of code:
EDIT: Just after posting this
strrpos()
solution, I found a best one: