I'd like to move an uploaded file to another directory, but have been wrestling with the settings and not sure if I have a config problem or a access rights issue.
I'm running php5 on a mac 10.4.8 with apache 1.3, and have copied and using some code for the upload procedure (see below).
As is it works as expected. File is selected and uploaded to /var/tmp, then temp filename is changed back original filename. All in the /var/tmp folder.
I'd like to move the uploaded file to the default doc folder for appache /Library/WebServer/Documents/.
It appears that apache or php can upload the file to /var/tmp, but if i manually try to copy with terminal, i do not have sufficient rights. I modified the php.ini setting for upload_tmp_dir to the Documents/ folder, and confirmed that phpinfo recognizes the change. But no luck, upload still goes to /var/tmp/.
I've also fiddled with the code below, to move out of the /var/tmp folder, but then I get the error about "possible file upload attack", and can't seem to move the file to a folder where I have full access to it.
So I guess I have 2 questions. Is there a way to really make the php.ini setting for upload_tmp_dir work, and/or is there a reason I can't easily move uploaded files from the /var/tmp folder to other folders. Why can php/apache do it, but as a user I can't do it manually or through code.
Thanks,
Jack 😕
<?php
$uploaddir = '/var/tmp/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo $uploadfile;
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>