note 32900 added to features.file-upload
| From: | olav-x at rack1 dot php dot net | Date: | Tue, 10 Jun 2003 13:11:50 +0000 |
| Subject: | note 32900 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50097@lists.php.net to get a copy of this message | ||
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><?
}
?>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32900
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32900&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32900&report=yes