note 25308 deleted from features.file-upload by philip

From: Date: Sat, 15 Feb 2003 15:47:10 +0000
Subject: note 25308 deleted from features.file-upload by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-44002@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"; ?>

« previous php.notes (#44002) next »