note 32900 deleted from features.file-upload by didou
| From: | didou@php.net | Date: | Tue, 10 Jun 2003 13:18:39 +0000 |
| Subject: | note 32900 deleted from features.file-upload by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50098@lists.php.net to get a copy of this message | ||
Note Submitter: olav-x AT volvo-power.net
----
Hi!
I had some problems with this script, so I converted the one I had to the new functions. my old one
used copy, and worked fine on linux / php.
When I tried to port it to windows/apache/php, it didnt work, and didnt output any error msg's.
I hope my script can help others with the sam problem.
ps. I think the only magic, was the $_FILES
I tried so much, I cant really remember what I started with :p
ps. this is to be used as beta.. it's not got any security filters or anything yet!!
ps. I didnt fix the "check if file is selected" function yet, but I guess you can manage
yourself.
here is the code:
<?
if (isset($_FILES['userfile'])) // if this var is set, we can upload
{
// Change $doc_directory to your 'DocumentRoot'.
$_POST['doc_directory'] = "c:\\apache\apache2\\htdocs\\tmp\\";
if ($_FILES['userfile'] != "none")
{
echo $_FILES['userfile'];
// the old function was: if(!copy($_FILES['users_file'] . "",
$_FILES['copy_path'] . ""))
if (!move_uploaded_file($_FILES['userfile']['tmp_name'],
$_POST['doc_directory'] . $_FILES['userfile']['name']))
{
echo "File upload failed!";
}
else
{
?><A HREF="<? echo $_POST['doc_directory'] .
$_FILES['userfile']['name']; ?>">Upload Complete!</A>
<?}
}
else
{
echo "<P>You must select a file to upload!<P>"; ?>
<A HREF="<? echo $_SERVER['PHP_SELF'];
?>"><B>Back</B></A> to the Upload Form
<?
} // end else
} // end if isset(user_file)
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>"
enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<input type="file" name="userfile" /><br />
<input type="submit" value="Upload!" name="a" />
</form><?
}
?>