I need to get the aboslute path of a file uploaded by the user in PHP. How can I do that? Im doing this cause I need to post the information to an API via cURL
+3
A:
The file path is stored in the $_FILES
array - just apply realpath
to that
realfile($_FILES['userfile']['tmp_name']);
A few points:
- Check that the file is the uploaded file with
is_uploaded_file
- Move it to a new location using
move_uploaded_file
- The API you're after will want a url for the file - rather than a file path - assuming the api is not on the same server
adam
2010-02-25 13:53:19
+1 Very nice answer
soulmerge
2010-02-25 13:54:15
Im actually building an API and want users to be able to upload files from sites that use the API. Ideally I didn't want to have to temporarily store it on the site's space, but it sounds like I will have to.
David
2010-02-25 13:58:37
Yeah - the http post upload functionality uploads it to the temp folder on the server, although you might be able to get round this using the more advanced uploaders available via YUI Library, for example
adam
2010-02-25 14:06:06
There is actually a way to do with without the need of uploading to the site using the API. If using cURL, just ad "@".realpath($_FILES['userfile']['tmp_name'])
David
2010-02-26 08:57:56