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
Asked
Active
Viewed 4,590 times
1 Answers
4
The file path is stored in the $_FILES
array - just apply realpath
to that
realpath($_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 Hopkinson
- 28,281
- 7
- 65
- 99
-
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 Feb 25 '10 at 13:58
-
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 Hopkinson Feb 25 '10 at 14:06
-
1There 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 Feb 26 '10 at 08:57