Bobo
Bobo

Reputation: 197

Uploaded picture in TMP is without file extension?

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

Upvotes: 3

Views: 4287

Answers (5)

Fahad Khan
Fahad Khan

Reputation: 21

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()

Upvotes: 0

Marc B
Marc B

Reputation: 360752

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.

Upvotes: 6

Matt Asbury
Matt Asbury

Reputation: 5662

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

Upvotes: 0

Seb Barre
Seb Barre

Reputation: 1647

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).

Upvotes: 0

jasonbar
jasonbar

Reputation: 13461

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.

Upvotes: 3

Related Questions