Here is one I designed for someone else a while back.
This program will let you select what type of files you want to allow for upload.
After you have uploaded the file, it will give you one chance to delete the file if you change your mind.
It is fairly easy to customize if you choose to.
PHP Code:
<?php session_start (); ?> <script> function selectAll() { var obj = document.getElementsByTagName("input"); for(var i=0;i<obj.length;i++) { if(obj[i].type == "checkbox") { obj[i].checked = "checked"; } } } </script><?php if(!empty( $_POST [ "resetFileTypes" ])){ unlink ( "fileTypes.txt" );} if(!empty( $_POST [ "fileTyps" ])) { $fp = fopen ( "fileTypes.txt" , "w" ); foreach( $_POST AS $value ){if( $value != "Submit" ){ fwrite ( $fp , $value . "\r\n" );}} fclose ( $fp ); } if(! file_exists ( "fileTypes.txt" )) { echo "<p><strong>Select file types to include.</strong></p> <form action='#' method='post'> <table border='1'> <tr><td><input type='checkbox' name='chkbx1' value='image/pjpeg'>image/pjpeg</td><td><input type='checkbox' name='chkbx2' value='image/jpeg'>image/jpeg</td></tr> <tr><td><input type='checkbox' name='chkbx3' value='image/gif'>image/gif</td><td><input type='checkbox' name='chkbx4' value='image/png'>image/png</td></tr> <tr><td><input type='checkbox' name='chkbx5' value='text/html'>text/html</td><td><input type='checkbox' name='chkbx6' value='text/plain'>text/plain</td></tr> <tr><td><input type='checkbox' name='chkbx7' value='text/xml'>text/xml</td><td><input type='checkbox' name='chkbx8' value='text/css'>text/css</td></tr> <tr><td><input type='checkbox' name='chkbx9' value='application/x-php'>application/x-php</td><td><input type='checkbox' name='chkbx10' value='application/javascript'>application/javascript</td></tr> <tr><td><input type='checkbox' name='chkbx11' value='application/octet-stream'>application/octet-stream</td><td><input type='checkbox' name='chkbx12' value='application/vnd.ms-excel'>application/vnd.ms-excel</td></tr> <tr><td><input type='checkbox' name='chkbx13' value='application/msword'>application/msword</td><td><input type='checkbox' name='chkbx14' value='application/pdf'>application/pdf</td></tr> <tr><td><input type='checkbox' name='chkbx15' value='application/msaccess'>application/msaccess</td><td><input type='checkbox' name='chkbx16' value='app/gg'>app/gg</td></tr> <tr><td colspan='2'> </td></tr> <tr><td><button onclick='selectAll()'>Select all</button><input type='reset' value='Reset'></td><td><input type='submit' name='fileTyps' value='Submit'></td></tr> </table> </form>" ; } else { $extensions = array( "jpg" , "JPG" , "gif" , "GIF" , "png" , "PNG" ); $msg = "" ; $target_path = "images/" ; if( file_exists ( "fileTypes.txt" )) { $fileTypes = array(); $fp = fopen ( "fileTypes.txt" , "r" ); while(! feof ( $fp )){ $fileTypes [] = trim ( fgets ( $fp ));} if(empty( $fileTypes [ 0 ])) { unlink ( "fileTypes.txt" ); header ( "location:" . $_SERVER [ "PHP_SELF" ]); } } $image = "" ; // Routine to upload and display file. // if(!empty( $_POST [ "upload" ]) && !empty( $_FILES [ "uploadedfile" ][ "size" ])) { if( in_array ( $_FILES [ 'uploadedfile' ][ 'type' ], $fileTypes )) { $_SESSION [ "name" ] = $_FILES [ 'uploadedfile' ][ 'name' ]; $_SESSION [ "file" ] = $target_path . $_SESSION [ "name" ]; if( move_uploaded_file ( $_FILES [ 'uploadedfile' ][ 'tmp_name' ], $_SESSION [ "file" ])) { if( in_array ( substr ( basename ( $_SESSION [ "file" ]),- 3 ), $extensions )){ $_SESSION [ "image" ] = "<img src='" . $_SESSION [ "file" ]. "' width='100' />" . "<p><b>" . $_SESSION [ "name" ]. "</b> has been uploaded successfully.</p>" ;} else{ $_SESSION [ "image" ] = "<p><b>" . $_SESSION [ "name" ]. "</b> has been uploaded successfully.</p>" ;} $_SESSION [ "image" ] .= "<form action='#' method='post'><input type='submit' name='delete' value='Delete File' style='float:left;' /><input type='submit' name='ulf' value='Upload another file' style='float:right;' /></form>" ; } else{ $msg = "There was an error uploading the file, please try again!" ;} } else{ $msg = "That file is not allowed." ;} } // Routine to delete file. // if(!empty( $_POST [ "delete" ])) { if( file_exists ( $_SESSION [ "file" ])) { unlink ( $_SESSION [ "file" ]); $msg = "<b>" . $_SESSION [ "name" ]. "</b> has been deleted." ; $_SESSION [ "file" ] = "" ; $_SESSION [ "name" ] = "" ; $_SESSION [ "image" ] = "" ; } } if(!empty( $_POST [ "ulf" ])) { $_SESSION [ "file" ] = "" ; $_SESSION [ "name" ] = "" ; $_SESSION [ "image" ] = "" ; } ?> <html> <head> <title>Upload Your Second Image</title> </head> <body> <?php if(!empty( $_SESSION [ "file" ])) { echo "<div style='width: 550px; border: solid #016ea7; margin-right:auto; margin-left:auto;'> <div style='background: #016ea7; color: #FFF'><p><strong>File Upload</strong></p></div> <div style='margin-bottom:20px;'>" . $_SESSION [ "image" ]. "</div> </div>" ; } else{ ?> <div style="width: 550px; border: solid #016ea7; margin-right:auto; margin-left:auto;"> <div style="background: #016ea7; color: #FFF"><p><strong>File Upload</strong></p></div> <div><?php echo $msg ; ?> </div> <form enctype="multipart/form-data" action="#" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> Choose a file to upload: <input name="uploadedfile" type="file" /> <p><input type="submit" name="upload" value="Upload File" style="float:left;"/><input type="submit" name="resetFileTypes" value="Reset file types" style="float:right;" /></p> </form> </div> </body> </html><?php }} ?>