note 33515 deleted from features.file-upload by didou
| From: | didou@php.net | Date: | Sun, 27 Jul 2003 16:07:41 +0000 |
| Subject: | note 33515 deleted from features.file-upload by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52749@lists.php.net to get a copy of this message | ||
Note Submitter: magnus.bonnevier@comhem.se
----
My Simple upload code that i put together with help off the manual here on PHP.net and some
imagination.
Some text parts might be in swedish but i´ll try to translate.
Decided to make my script a little more usable.
So i added a option to change the upload dir instead
using the default one.
My enligsh might be a little rusty.
Hope you get some ideas.
This script resides in a file called upload.php.
But you could probaly change it to fit your needs.
<?PHP if ( $_POST['action'] == "upload" ) { ?>
<?PHP if ( $_POST['select_custom_upload_dir'] == "yes") { ?>
<?PHP $uploaddir = "" . $_POST['custom_upload_dir'] . ""; ?>
<?PHP } else { ?>
<?PHP $uploaddir = '/www-root/htdocs/image/'; ?>
<?PHP } ?>
<?PHP
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploaddir .
$_FILES['uploadfile']['name'])) {
echo("MAX_FILE_SIZE in html-form: " . $_POST['MAX_FILE_SIZE'] . "
Bytes.<BR>");
echo("File uploaded to: " . $uploaddir . "<BR>");
echo("File uploaded: " . $_FILES['uploadfile']['name'] .
"<BR>");
echo("File type uploaded: " . $_FILES['uploadfile']['type'] .
"<BR>");
echo("Size of file uploaded in bytes: " .
$_FILES['uploadfile']['size'] . "<BR>");
echo("Temp name of file uploaded on server: " .
$_FILES['uploadfile']['tmp_name'] . "<BR>");
} else {
echo("Error!<BR>");
if ( $_FILES['uploadfile']['error'] == "0" ) {
echo("Value 0, No problem, the file is uploaded.<BR><P>");
} elseif ( $_FILES['uploadfile']['error'] == "1" ) {
echo("Value 1; The uploaded file was bigger then upload_max_filesize in php.ini.
<BR><P>");
} elseif ( $_FILES['uploadfile']['error'] == "2" ) {
echo("Value 2; The uploaded file was bigger then MAX_FILE_SIZE in
html-form.<BR><P>");
} elseif ( $_FILES['uploadfile']['error'] == "3" ) {
echo("Value 3; File partialy uploaded.<BR><P>");
} elseif ( $_FILES['uploadfile']['error'] == "4" ) {
echo("värde 4; No file was uploaded.<BR><P>");
} else {
echo("" . $_FILES['uploadfile']['error'] .
"<BR><P>");
}
}
?>
<BR><P>
<A HREF='upload.php' target='_parent'>Go back</A>
<?PHP } else { ?>
Upload file<BR><P>
<form action='upload.php' method='post'
enctype='multipart/form-data'>
<input type='hidden' name='MAX_FILE_SIZE' value='1000000'>
File to upload: <input type='file' name='uploadfile'><BR><P>
<input type='hidden' name='action' value='upload'>
<hr align='left' size='1' color='#C0C0C0' noshade>
<input type='radio' name='select_custom_upload_dir' value='yes'>
Custom upload dir: <input type='text' name='custom_upload_dir'
size='50' maxlength='55'
VALUE='/www-root/htdocs/'><BR><P>
<input type='submit' value='Upload'>
</form>
<?PHP } ?>