PDA

View Full Version : File Upload Error



Titan85
01-13-2007, 03:46 PM
I created a little script to upload files, but I keep getting an error while uploading. Here is my code:
<?php

if($_POST['upload']) {

$path = $_POST['path'];
$upload_path = $path . basename($_FILES['file']['name']);

if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {

echo 'The file: '.$_FILES['file']['name'].' has been uploaded. <br /> Details:';
echo 'File Type '.$_FILES['file']['type'].' <br />
File Size: '.$_FILES['file']['size'].' <br />
File Name: '.$_FILES['file']['name'].'';
}

else {

echo 'There was an error while uploading the file!';
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<b>File To Upload</b>:
<br />
<input type="file" name="file" />
<br /><br />
<b>Directory To Upload To</b>:
<br />
<input type="text" name="path" value="/directory" />
<br /><br />
<input type="submit" name="upload" value="Upload" />
</form>I chmodded the directory I am uploading to to 777 and all, but I still get the error: "
Warning: move_uploaded_file(uploads/): failed to open stream: Is a directory in /home/bntqann/public_html/testing/file_upload/upload.php on line 8

Warning: move_uploaded_file(): Unable to move '/tmp/phpCNrQ1u' to 'uploads/' in /home/bntqann/public_html/testing/file_upload/upload.php on line 8
There was an error while uploading the file!". I am at a loss as to why it is giving the error, I appreciate any help :)

alexjewell
01-13-2007, 04:47 PM
Haha, this is so the one I wrote
A LONG time ago.

I finally gave up on this particular code and started from scratch.

There's 3 files, though, so there's too much code to post here.
Next time you're on aim, I'll send them to you?

Titan85
01-14-2007, 03:52 AM
Haha, this is so the one I wrote
A LONG time ago.

I finally gave up on this particular code and started from scratch.

There's 3 files, though, so there's too much code to post here.
Next time you're on aim, I'll send them to you?Your code is fancier lol.
Anyone see an issue with my code that would be causing the error?

mike_p
01-15-2007, 12:29 PM
based on a quick look... does the destination path exist?

Titan85
01-15-2007, 04:55 PM
based on a quick look... does the destination path exist?Yeah, I checked it a few times to make sure

thetestingsite
01-15-2007, 04:59 PM
I noticed you had these two lines of code in your php, but I don't know why.



$path = $_POST['path'];
$upload_path = $path . basename($_FILES['file']['name']);


Then you have in this line for the destination, $path:



move_uploaded_file($_FILES['file']['tmp_name'], $path)


Then in the rest of the script (unless you call it somewhere else), you never call upon the $upload_path variable. Maybe try switching $path with $upload_path.

Just a suggestion.

Titan85
01-15-2007, 05:27 PM
Thanks man, that was it. I put $path where I should have put $upload_path

thetestingsite
01-15-2007, 05:32 PM
Simple mistake, happens all the time. What's even worse is when you can't find what mistake you made.