I have a simple file upload script that works just fine as long as I only upload to /tmp. If I try to upload (using move_uploaded_file) to, for instance, /tmp/uploads or /uploads (both of which already exist, are owned by apache:apache, and have 777 permissions), I get the dreaded "failed to open stream" and "unable to move" errors.
Can anyone tell me how to get it working so that I can upload to other directories? I've tried a couple of changes to /etc/php.ini (upload_tmp_dir), but I think it is the default configuration right now (safe_mode is Off). httpd.conf is also the default configuration, if I'm not mistaken.
I am using Fedora 14, Apache 2, and PHP 5.
I would definitely appreciate any help! 🙂
Note: this script is from O'Reilly's PHP Cookbook.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET' ) {
?>
<form method="post" action="phpcookbook.php"
enctype="multipart/form-data">
<input type="file" name="document"/>
<input type="submit" value="Send File"/>
</form>
<?php
} else {
if (isset($_FILES['document']) &&
($_FILES['document']['error'] == UPLOAD_ERR_OK)) {
$newPath = '/uploads/' . basename($_FILES['document']['name']);
#$newPath = '/tmp/' . basename($_FILES['document']['name']);
#$newPath = '/tmp/uploads/' . basename($_FILES['document']['name']);
if (move_uploaded_file($_FILES['document']['tmp_name'], $newPath)) {
print "File saved in $newPath";
} else {
print "couldn't move file to $newPath";
}
} else {
print "No valid file uploaded.";
}
}
?>