Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_FILES['file']['tmp_name']: How to preserve filename and extension?

Tags:

php

I am trying to upload a doc file from a form and send it to email. I am using

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

The problem is, it is returning a randomly generated file name. So, when it reaches the inbox, the filename is phpvwRGKN.dat (filename is random each time).

How can I preserve the filename and extension?

Note: I am using geekMail class

like image 695
Jaspero Avatar asked Oct 15 '10 19:10

Jaspero


2 Answers

$_FILES['file']['tmp_name']; will contain the temporary file name of the file on the server. This is just a placeholder on your server until you process the file

$_FILES['file']['name']; contains the original name of the uploaded file from the user's computer.

like image 192
Alan Geleynse Avatar answered Oct 31 '22 13:10

Alan Geleynse


$_FILES["file"]["name"] - the name of the uploaded file

from http://www.w3schools.com/php/php_file_upload.asp

like image 10
Gabi Purcaru Avatar answered Oct 31 '22 12:10

Gabi Purcaru