PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi I'm having problems uploading a file to a server running vista, I would be grateful for any help. Sorry if this has been answered before.
The errors I'm getting are:
[error] [client 192.168.1.50] PHP Warning: move_uploaded_file(C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Applet) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: Permission denied in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\upload.php on line 7
[error] [client 192.168.1.50] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'C:\\Windows\\Temp\\phpDECE.tmp' to 'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Applet' in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\upload.php on line 7
I came across a similar problem a while ago, I only managed to fix it by deleting the directory and making it again through the script using mkdir. But if you have the chmod function available try changing the permissions of the dir to 666 (for windows I think), or else 0777. Hope that helps a bit.
<?
if(is_file($_FILES['uploadedfile']['tmp_name'])){
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path))
{
echo "The file ".basename($_FILES['uploadedfile']['name'])." has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}
}else{
echo "There was an error uploading the file, please try again!";
}
?>
Last edited by Benjamin on Tue Apr 28, 2009 1:35 pm, edited 1 time in total.
Reason:Changed code type from text to php.
I tried installing apache in c:\apache but I'm still getting the same error. Is there anything else I can try? I really need to get this working this week
<p>Warning: An uploaded file will overwrite an existing file with the same name if one exists.</p>
<form method="post" action="file-upload-debugger-2.php" enctype="multipart/form-data">
<input type="file" name="uploadedFile" />
<input type="submit" value="Upload" />
</form>
<pre><?php
echo '$_FILES => ';
print_r($_FILES);
if (!empty($_FILES)) {
$tmp_name =& $_FILES['uploadedFile']['tmp_name'];
if (is_file($tmp_name)) {
echo 'Found temporary file at '.$tmp_name."\n";
$name =& $_FILES['uploadedFile']['name'];
$dest = './'.$name;
if (move_uploaded_file($tmp_name, $dest)) {
echo 'File successfully moved to '.$dest."\n";
} else {
echo 'Failed to move file to '.$dest."\n";
$dest = getcwd().'/'.$name;
if (move_uploaded_file($tmp_name, $dest)) {
echo 'File successfully moved to '.$dest."\n";
} else {
echo 'Failed to move file to '.$dest."\n";
}
}
} else {
echo 'Cannot find temporary file at '.$tmp_name."\n";
}
}
?></pre>
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 12:53 pm, edited 1 time in total.
Found temporary file at C:\Windows\Temp\php3015.tmp
File successfully moved to ./test.txt
The file moved correctly and everything seems to work. The problem now is I need to upload the file through a java program, how would I edit the script to allow this?
Thanks for you help so far.
Last edited by Benjamin on Tue Apr 28, 2009 1:35 pm, edited 2 times in total.
Reason:Added code tags.