Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <form enctype="multipart/form-data" action="upload_file.php" method="POST">
  2. Choose a file to upload: <input name="uploaded" type="file" /><br />
  3. <input type="submit" value="Upload File" />
  4. </form>
  5.  
  6. <?php
  7. $target = "upload/";
  8. $target = $target . basename( $_FILES['uploaded']['name']) ;
  9. $ok=1;
  10. $uploaded_type= $_FILES['uploaded']['type'];
  11. $uploaded_size= $_FILES['uploaded']['size'];
  12.  
  13. //This is our size condition
  14. if ($uploaded_size > 350000)
  15. {
  16. echo "Your file is too large.<br>";
  17. $ok=0;
  18. }
  19.  
  20. //This is our limit file type condition
  21. if ($uploaded_type =="text/php")
  22. {
  23. echo "No PHP files<br>";
  24. $ok=0;
  25. }
  26.  
  27. //Here we check that $ok was not set to 0 by an error
  28. if ($ok==0)
  29. {
  30. Echo "Sorry your file was not uploaded";
  31. }
  32.  
  33. //If everything is ok we try to upload it
  34. else
  35. {
  36. if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
  37. {
  38. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  39. }
  40. else
  41. {
  42. echo "Sorry, there was a problem uploading your file.";
  43. }
  44. }
  45. ?>
  46.  
  47. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  48.  
  49. echo '<pre>';
  50. print_r($_FILES);
  51. echo '<pre>';
  52.  
  53. <?php
  54.  
  55. if (TRUE) {
  56. echo '<pre>';
  57. print_r($_FILES);
  58. echo '<pre>';
  59. }
  60.  
  61. $ok = TRUE;
  62.  
  63. // Check if there is an uploaded file.
  64. if (!array_key_exists('uploaded', $_FILES) && !empty($_FILES['uploaded'])) {
  65. echo "Sorry, no file seems to be uploaded.";
  66. $ok = FALSE;
  67. }
  68.  
  69. $target = "upload/";
  70. $target = $target . basename($_FILES['uploaded']['name']) ;
  71. $uploaded_type = $_FILES['uploaded']['type'];
  72. $uploaded_size = $_FILES['uploaded']['size'];
  73.  
  74. // This is our size condition.
  75. if ($uploaded_size > 350000) {
  76. echo "Your file is too large.<br>";
  77. $ok = FALSE;
  78. }
  79.  
  80. //This is our limit file type condition
  81. if ($uploaded_type =="text/php") {
  82. echo "No PHP files<br>";
  83. $ok = FALSE;
  84. }
  85.  
  86. // Here we check that $ok was not set to 0 by an error
  87. if ($ok) {
  88. echo "Sorry your file was not uploaded";
  89. }
  90. // If everything is ok we try to upload it
  91. else {
  92. if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
  93. echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
  94. }
  95. else {
  96. echo "Sorry, there was a problem uploading your file.";
  97. }
  98. }
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement