note 25308 added to features.file-upload

From: Date: Wed, 18 Sep 2002 23:07:19 +0000
Subject: note 25308 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-36944@lists.php.net to get a copy of this message
Here is how to upload and check if the file is valid: <form action="postPic.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <input name="photo" type="file"> <input type="submit" name="Submit" value="Upload file"> </form> postPic.php: ------------ <?php echo "photo_name: $photo_name<br> photo: $photo<br> photo_size: $photo_size<br><br>"; //checks if the input is filled. could use $photo != "none". if($photo_size){ //Checks for file type: $ext=substr($photo_name,-4); //strcasecmp used for .jpg <> .JPG if (strcasecmp($ext,".jpg") || strcasecmp($ext,".gif") || strcasecmp($ext,".bmp")){ //Saving the photo: if(is_uploaded_file($photo)){ $photoFile = "photos/photo1.jpg"; move_uploaded_file($photo, $photoFile); //Add this lines to update your database: //$query = "UPDATE $curDb SET photoFile='$photoFile'"; //mysql_query($query); echo "picture uploaded to ./photos/photo1.jpg"; } } //error msg, non valid extention: else die("file type non valid, use .jpg, .gif or .bmp"); } //the HTML form <input type="hidden" name="MAX_FILE_SIZE" value="200000"> //sets $photo_size to 0 if the file > 200k else if($photo_name != "" && $photo_size == "0") die("size file must be smaller than 200k"); else echo "no file selected"; ?> -- http://www.php.net/manual/en/features.file-upload.php http://master.php.net/manage/user-notes.php?action=edit+25308 http://master.php.net/manage/user-notes.php?action=delete+25308 http://master.php.net/manage/user-notes.php?action=reject+25308

« previous php.notes (#36944) next »