file handling
|file upload
an easy file upload script.
specify the filetypes allowed, the max filesize and the directory to upload the files.
full source of file upload [ line 1 - 53 ] | download file upload
| 1 | <?php |
| 2 | // specify the directory where the uploaded file should end up |
| 3 | $path = 'upload/' ; |
| 4 | // specify the filetypes allowed |
| 5 | $allowed = array('image/gif','image/pjpeg','image/jpeg','image/png'); |
| 6 | // specify the max filesize in bytes |
| 7 | $max_size = 200000; |
| 8 | if(isset($HTTP_POST_FILES['userfile'])) |
| 9 | { |
| 10 | if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) |
| 11 | { |
| 12 | if($HTTP_POST_FILES['userfile']['size'] < $max_size) |
| 13 | { |
| 14 | if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed)) |
| 15 | { |
| 16 | if(!file_exists($path . $HTTP_POST_FILES['userfile']['name'])) |
| 17 | { |
| 18 | if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name'])) |
| 19 | { |
| 20 | $html_output = 'Upload sucessful!<br>'; |
| 21 | $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>'; |
| 22 | $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>'; |
| 23 | $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br>'; |
| 24 | $image = $HTTP_POST_FILES['userfile']['name'] ; |
| 25 | }else{ |
| 26 | $html_output = 'Upload failed!<br>'; |
| 27 | if(!is_writeable($path)) |
| 28 | { |
| 29 | $html_output = 'The Directory "'.$path.'" must be writeable!<br>'; |
| 30 | }else{ |
| 31 | $html_output = 'an unknown error ocurred.<br>'; |
| 32 | } |
| 33 | } |
| 34 | }else{ |
| 35 | $html_output = 'The file already exists<br>'; |
| 36 | } |
| 37 | }else{ |
| 38 | $html_output = 'Wrong file type<br>'; |
| 39 | } |
| 40 | }else{ |
| 41 | $html_output = 'The file is too big<br>'; |
| 42 | } |
| 43 | } |
| 44 | }else{ |
| 45 | $html_output = '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">'; |
| 46 | $html_output .= '<input type="file" name="userfile">'; |
| 47 | $html_output .= '<input type="submit" value="upload">'; |
| 48 | $html_output .= '</form>'; |
| 49 | } |
| 50 | echo '<html><head><title>Uploader</title></head><body>'; |
| 51 | echo $html_output; |
| 52 | echo '</body></html>'; |
| 53 | ?> |
5 hits by 2 users in the last 30 minutes.