user3335903
user3335903

Reputation: 1565

Proper use of move_uploaded_file()

I used this tag to move my uploaded files to a directory, and it seems that it didn't worked as planed. This is what my code looks like:

$tmp = $_FILES['file']['tmp_name'];
$location = "/var/www/images/";

move_uploaded_file($tmp, "$location.$tmp");

Did I supplied the correct arguement? If not, what could be the answer to my problem?

Thank you in advance. :)

Upvotes: 0

Views: 68

Answers (3)

Sagar Rabadiya
Sagar Rabadiya

Reputation: 4321

$location = "/var/www/images/".$_FILES['file']['name'];

move_uploaded_file($_FILES['file']['tmp_name'], $location);

Upvotes: 1

Krish R
Krish R

Reputation: 22721

Try this, You need to use name instead of tmp_name

$filename = $_FILES['file']['name'];
move_uploaded_file($tmp, "$location.$filename");

Upvotes: 1

PravinS
PravinS

Reputation: 2584

you must use $_FILES['file']['name'] while giving name to uploading file, try using like this

$tmp = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$location = "/var/www/images/";

move_uploaded_file($tmp, "$location.$name");

Upvotes: 2

Related Questions