note 33515 added to features.file-upload

From: Date: Sat, 28 Jun 2003 11:31:38 +0000
Subject: note 33515 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-51133@lists.php.net to get a copy of this message
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 } ?> ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33515 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33515&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33515&report=yes

« previous php.notes (#51133) next »