/ Published in: PHP
simple php file uploader with check for file extension and size.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<html> <head> </head> <body> <? $AllowedSize = (1 * 1024 * 1024); //=>bytes. ?> <h2>Uploaded File Info:</h2> <ul> <li>temp file: <?php echo $_FILES["file"]["tmp_name"]; ?> <li>Sent file: <?php echo $_FILES['file']['name']; ?> <li>File size: <?php echo $_FILES['file']['size']; ?> bytes <li>File type: <?php echo $_FILES['file']['type']; ?> <li>File Extension: <?php echo $extension; ?> </ul> <? if ($_FILES["file"]["size"] > $AllowedSize){ echo '<font face="Tahoma" size="3" color="#F00000" ><b>The size of "'. $_FILES["file"]["name"] .'" file is more than '. ($AllowedSize / (1024*1024)).' Mb. </b></font>'; return 0; } echo '<font face="Tahoma" size="3" color="#F00000" ><b>"'. $_FILES["file"]["name"] .'" - not accepted file. </b></font>'; return 0; } if ($_FILES["file"]["error"] > 0){ echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; return 0; } echo '<font face="Tahoma" size="3" color="#F00000" ><b>"'. $_FILES["file"]["name"] .'" - already exists. </b></font>'; else{ $_FILES["file"]["name"]); echo '<font face="Tahoma" size="3" color="#008000" ><b>"'. $_FILES["file"]["name"].'" - was successfully uploaded.</b></font>'; } ?> </body> </html>
URL: http://function-code.blogspot.com/2013/10/how-to-upload-files-or-images-using-php.html