3

Please,

After uploading picture, file is still in TMP folder, and when I echo:

$_FILES['file']['tmp_name'] 

Im getting, for example:

/tmp/phpZnmIfT 

So uploaded picture is without extension?! Is this "normal" or some Php GD configuration is missing?

Thanks in advance

5 Answers 5

6

PHP stores the file using a temporary name, which is what you're seeing. After all, two or more people might upload the same "file.doc", and if PHP was using that name to store it on the server, one would overwrite the other.

You can retrieve the original client-side filename with $_FILE['file']['name']. Full details on the structure of the $_FILE array is here.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for the manual reference - Note that (contrary to what some people want to believe) you won't necessarily get the original client directory path and filename, just the filename
Thankfully the sane browsers strip out the path info, since that'd be somewhat of a privacy hole.
3

Files are uploaded to the temp directory with a unique (and temporary) name.

You have to move the file to the final location and name it appropriately using move_uploaded_file().

The first usage example is what you want.

Comments

0

If you examine the rest of the $_FILES array for your upload, you will get the original upload name, as well as the mime-type of the file that was uploaded, which you can use to perform further actions on the file post-upload (like move/rename it using move_uploaded_file() as the previous poster suggests).

Comments

0

Yes it's normal. The file type (MIME type) is stored in $_FILES['userfile']['type']

Comments

0

You can get the original filename as follows: if you are getting the file in your controller as:

$logo = $request->file('companyLogo'); 

then $logo->getClientOriginalName() can give you original file name, also you cna check for original extension and file size as follows:

$logo->getClientOriginalExtension() $logo->getSize() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.