Reputation: 197
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
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
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
Reputation: 5662
Yes it's normal. The file type (MIME type) is stored in $_FILES['userfile']['type']
Upvotes: 0
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
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