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

Bobo
  • 197
  • 1
  • 2
  • 7

5 Answers5

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.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • +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 – Mark Baker Jan 14 '11 at 16:19
  • Thankfully the sane browsers strip out the path info, since that'd be somewhat of a privacy hole. – Marc B Jan 14 '11 at 16:24
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.

jasonbar
  • 13,333
  • 4
  • 38
  • 46
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).

Seb Barre
  • 1,597
  • 1
  • 12
  • 17
0

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

Matt Asbury
  • 5,644
  • 2
  • 21
  • 29
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()
Fahad Khan
  • 21
  • 1
  • 6