Log in

View Full Version : php upload script



boxxertrumps
03-11-2007, 09:17 PM
if ($action == "load") {
if(!empty($_FILES["userfile"])) {
$uploaddir = $home . $path . $_FILES["userfile"]["name"];
//Copy the file to some permanent location
if(move_uploaded_file($_FILES[userfile]["tmp_name"], $uploaddir)) {
echo 'The file was uploaded successfully! Please click <a href="?path='.$path.'">here</a> to continue.';
} else {
echo 'An error occured while trying to upload the file! Please click <a href="?path='.$path.'">here</a> to return to the File Manager.';
print_r($_FILES);
}
} else {print_r($_REQUEST);}
} else {
echo '<form method="POST">
<input type="hidden" name="action" value="load" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Upload" />
</form>';
}

}
I get the Request data(will be taken out once the scipt works) instead of a conformation message.
Im doing something wrong, but i dont know what.
PS: "$_FILES" is not empty, b/c i get this...
Array ( [path] => upload/ [act] => load [action] => load [userfile] => /home/boxxertrumps/snapshot1.png )

thetestingsite
03-12-2007, 09:11 PM
You have to put in the enctype as multipart/form-data. An example:



<form method="POST" enctype="multipart/form-data">


That should do it. Hope this helps.

mburt
03-12-2007, 09:18 PM
Yep, you have to use it when using the pre-defined $_FILES variable. Look here for why:
http://www.htmlcodetutorial.com/forms/_FORM_ENCTYPE.html

boxxertrumps
03-13-2007, 12:36 AM
First time writing an upload *anything*... thanks.

Upload works now... should have done more research.