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
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.
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.
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).
Yes it's normal. The file type (MIME type) is stored in $_FILES['userfile']['type']
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()
精彩评论