tags:

views:

82

answers:

3

This is the PHP code used for the upload:

$upload = "uploads/";
$upload = $upload . basename($_FILES['bgimage']['name']);

if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) {

    echo "The file has been uploaded successfully.";

} else { echo "Error"; }

When I test the script, it says "The file has been uploaded successfully." but when I check the FTP server, it hasn't really...

Also, if you need to know, here's the HTML codes:

Form tag:

<form name="profilestyle" action="account.php?action=profiletheme" method="post" enctype="multipart/form-data">

Input tag:

<input type="file" name="bgimage" />

Extra Information: Yes, I remembered the CHMod the uploads directory

+1  A: 

Odd, the code looks fine as far as I can see.

Can you use file_exists() to check whether the file exists, but maybe is not visible to your FTP user?

if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) {

echo "The file '$upload' has been uploaded successfully.";
if (file_exists($upload)) echo "And it exists! It is ".filesize($upload)." bytes big.";
 else echo "But it doesn't exist.";

} else { echo "Error"; }
Pekka
A: 

Please try the following test code

$upload = "uploads/";
$upload = $upload . basename($_FILES['bgimage']['name']);

sprintf('<pre>Debug: moving file from %s to %s</pre>',
  $_FILES['bgimage']['tmp_name'],
  $upload
);
if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) {
  echo "The file has been uploaded successfully.";
  sprintf('<pre>Debug: realpath=%s, filesize=%d</pre>',
    realpath($upload),
    filesize($upload)
  );
}
else {
  echo "Error";
}

and esp. keep an eye on the realpath=xyz output.

VolkerK
+1  A: 

You also need to check $_FILES['bgimage']['error'] to make sure it is equal to UPLOAD_ERR_OK and is not an error code.

Justin Ethier