I'm running into problems with a simple file upload. The error message indicates that it is a permission problem, but all the paths involved in this are set to 777 permissions.
Boiled down to its essence the code is this:
<?php
if ($HTTP_POST_VARS['submit']) {
echo '<pre>';
print_r($_FILES);
echo '</pre>';
$result = move_uploaded_file($_FILES['file']['tmp_name'], "images/coupons/" . $_FILES['file']['name']);
if ($result) {
print '<br>File has been successfully uploaded! MoveResult was:' . $result . '<br>';
} else {
print 'File FAILED to upload! MoveResult was:' . $result . '<br>';
}
}
?>
<html>
<head></head>
<body>
<form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
<br><br>
Choose a file to upload:<br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Here is the output from running the code:
Array
(
[file] => Array
(
[name] => 4aa.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpaSNfJ6
[error] => 0
[size] => 84185
)
)
Warning: move_uploaded_file(images/coupons/4aa.jpg): failed to open stream:
Permission denied in /home/w4ralphy/public_html/zzz2.php on line 8
Warning: move_uploaded_file():
Unable to move '/tmp/phpaSNfJ6' to 'images/coupons/4aa.jpg'
in /home/w4ralphy/public_html/zzz2.php on line 8
File FAILED to upload! MoveResult was:
I've also tried to see if the first step of the process - uploading the file to the tmp directory - is working as it should by adding an is_uploaded_file() check and commenting out the move_uploaded_file() code:
if (is_uploaded_file ($_FILES['file']['tmp_name'])) {
echo "File moved to tmp directory";}
Although is_uploaded_file() indicates that the first step succeded, I haven't been able to find any evidence of the temp file on the server.