Page 1 of 1
Upload error
Posted: Sun Apr 26, 2009 5:02 pm
by nen29
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
Code: Select all
<?php
$target_path = "C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Applet";
$target_path = $target_path.basename($_FILES['uploadedfile']['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!";
}
?>
Re: Upload error
Posted: Sun Apr 26, 2009 5:26 pm
by ben.artiss
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.
Re: Upload error
Posted: Sun Apr 26, 2009 6:50 pm
by McInfo
Install Apache somewhere other than Program Files, like C:\apache.
Edit: This post was recovered from search engine cache.
Re: Upload error
Posted: Sun Apr 26, 2009 7:40 pm
by theskyeagle
Try this:
Code: Select all
<?
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!";
}
?>
Re: Upload error
Posted: Mon Apr 27, 2009 3:59 pm
by nen29
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
Re: Upload error
Posted: Mon Apr 27, 2009 4:20 pm
by McInfo
What is the output of this script after you upload a file with it?
file-upload-debugger.php
Code: Select all
<p>File uploads is <?php echo ini_get('file_uploads'); ?></p>
<p>Upload attempts: <?php echo ($attempts = isset($_POST['attempts']) ? $_POST['attempts'] + 1 : 0); ?></p>
<form method="post" action="file-upload-debugger.php" enctype="multipart/form-data">
<input type="hidden" name="attempts" value="<?php echo $attempts; ?>" />
<input type="file" name="uploadedFile" />
<input type="submit" value="Upload" />
</form>
<pre>$_FILES => <?php print_r($_FILES); ?></pre>
Edit: This post was recovered from search engine cache.
Re: Upload error
Posted: Mon Apr 27, 2009 4:58 pm
by nen29
McInfo wrote:What is the output of this script after you upload a file with it?
file-upload-debugger.php
Code: Select all
<p>File uploads is <?php echo ini_get('file_uploads'); ?></p>
<p>Upload attempts: <?php echo ($attempts = isset($_POST['attempts']) ? $_POST['attempts'] + 1 : 0); ?></p>
<form method="post" action="file-upload-debugger.php" enctype="multipart/form-data">
<input type="hidden" name="attempts" value="<?php echo $attempts; ?>" />
<input type="file" name="uploadedFile" />
<input type="submit" value="Upload" />
</form>
<pre>$_FILES => <?php print_r($_FILES); ?></pre>
$_FILES => Array
(
[uploadedFile] => Array
(
[name] => test.txt
[type] => text/plain
[tmp_name] => C:\Windows\Temp\php1451.tmp
[error] => 0
[size] => 15
)
)
Re: Upload error
Posted: Mon Apr 27, 2009 5:40 pm
by McInfo
Another script for you to try...
file-upload-debugger-2.php
Code: Select all
<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.
Re: Upload errorhttp://forums.devnetwork.net/posting.php?mode=re
Posted: Tue Apr 28, 2009 5:19 am
by nen29
Hi thanks for the help
The output I get is -
Code: Select all
$_FILES => Array
(
[uploadedFile] => Array
(
[name] => test.txt
[type] => text/plain
[tmp_name] => C:\Windows\Temp\php3015.tmp
[error] => 0
[size] => 15
)
)
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.
Re: Upload error
Posted: Tue Apr 28, 2009 12:35 pm
by McInfo
A Java applet should be able to send a POST request to your PHP script.
If you dig through the
source code of JUpload, you can find an example.
Edit: This post was recovered from search engine cache.