Anna_Kurmanova

file upload version 2 w/html

May 6th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_FILES['UploadFileField'])){
  4.  
  5. // Creates the Variables needed to upload the file
  6.  
  7. $UploadName = $_FILES['UploadFileField']['name'];
  8. $UploadName = mt_rand(100000, 999999).$UploadName;
  9. $UploadTmp = $_FILES['UploadFileField']['tmp_name'];
  10. $UploadType = $_FILES['UploadFileField']['type'];
  11. $FileSize = $_FILES['UploadFileField']['size'];
  12.  
  13. // Removes Unwanted Spaces and characters from the files names of the files being uploaded
  14.  
  15. $UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
  16.  
  17. // Upload File Size Limit
  18.  
  19. if(($FileSize > 125000)){
  20.  
  21. die("Error - File too Big");
  22.  
  23. }
  24.  
  25. // Checks a File has been Selected and Uploads them into a Directory on your Server
  26.  
  27. if(!$UploadTmp){
  28. die("No File Selected, Please Upload Again");
  29. }else{
  30. move_uploaded_file($UploadTmp, "Upload/$UploadName");
  31. }
  32. }
  33. ?>
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. <!DOCTYPE html>
  43. <html>
  44. <head>
  45. <style>
  46. body {
  47. margin:0px;
  48. padding:0px;
  49. background:#CCC;
  50. }
  51. .fileuploadholder {
  52. width:400px;
  53. height:400px;
  54. margin:60 px auto 0px auto;
  55. background:#FFF;
  56. border:1px solid #CCC;
  57. padding:6px;
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. </style>
  65.  
  66.  
  67.  
  68.  
  69. <title>File Upload</title>
  70.  
  71.  
  72.  
  73. </head>
  74. <body>
  75.  
  76. <div class = "fileuploadholder">
  77. <form action = "fileupload.php" method = "post" enctype = "multipart/form-data" name = "FileUploadForm" id = "FileUploadForm" >
  78. <label for = "UploadFileField"></label>
  79. <input type = "file" name = "UploadFileField" id = "UploadFileField">
  80. <input type = "submit" name = "UploadButton" id = "UploadButton">
  81.  
  82. </form>
  83.  
  84. </div>
  85.  
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment