bagus
bagus

Reputation: 3

PHP move uploaded file always error

I post a file by HTML and I want to move it but it always return value false. here's my code :

$fileName = $_FILES['atc']['name'];
$fileTmp = $_FILES['atc']['tmp_name'];

$newDir = "/home/goes/attachments/" . $fileName;

$a = move_uploaded_file($fileTmp, $newDir);

if ($a==true){
 echo "true";
}

else{
 echo "false";
}

Upvotes: 0

Views: 92

Answers (3)

Thomas Tkr
Thomas Tkr

Reputation: 49

The destination folder may not be have write permission

Upvotes: 1

Pine
Pine

Reputation: 74

foreach ($_FILES['atc']['tmp_name'] as $key => $tmp_name){
$path = "home/goes/attachments/" . $fileName";
move_uploaded_file($tmp_name, $path); }

Upvotes: 0

Borniet
Borniet

Reputation: 3546

  1. Check the content of all of your variables, see if they contain anything (good)
  2. Check if the directory where you want to place the files exists, and is writeable by the webserver (or whoever runs the PHP process).
  3. Is this the script you are calling from your form? Apache only holds the uploaded files for the duration of the called script, after that, the files are deleted if they are not handled by the script.

Upvotes: 0

Related Questions