Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. <form id="insert_movie" action="upload_file.php" method="post" enctype="multipart/form-data">
  2. <label for="file">Filename:</label>
  3. <input type="file" name="file" id="file"><br>
  4. <input type="submit" name="submit" value="Submit">
  5. </form>
  6.  
  7. //Upload the image
  8. $allow = array("jpg", "jpeg", "gif", "png");
  9.  
  10. $todir = 'images/';
  11.  
  12. if(isset($_POST['submit'])){
  13. if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
  14. {
  15. $info = explode('.', strtolower( $_FILES['file']['name']) ); // whats the extension of the file
  16.  
  17. if ( in_array( end($info), $allow) ) // is this file allowed
  18. {
  19. if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
  20. {
  21. echo "this doesn't work";
  22. }
  23. }
  24. else
  25. {
  26. // error this file ext is not allowed
  27. echo "this doesn't work either";
  28. }
  29. }
  30. }
  31. echo "however this works perfectly";
  32. ?>
  33.  
  34. if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
  35.  
  36. if ( $_FILES['file']['tmp_name'] ) // is the file uploaded yet?
  37.  
  38. <?php
  39.  
  40. //Upload the image
  41. $allow = array("jpg", "jpeg", "gif", "png");
  42.  
  43. $todir = 'images/';
  44.  
  45. if(isset($_POST['submit'])){
  46. // if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
  47.  
  48. if ( $_FILES['file']['tmp_name'] ) // is the file uploaded yet?
  49. {
  50. $info = explode('.', strtolower( $_FILES['file']['name']) ); // whats the extension of the file
  51.  
  52. if ( in_array( end($info), $allow) ) // is this file allowed
  53. {
  54. if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
  55. {
  56. echo "Success";
  57. }
  58. }
  59.  
  60.  
  61. else
  62. {
  63. // error this file ext is not allowed
  64. echo "Sorry, this is now allowed.";
  65. }
  66. }
  67.  
  68. }
  69. // echo "however this works perfectly";
  70. ?>
  71.  
  72. enctype="multipart/form-data"
  73.  
  74. $path = dirname(__FILE__).'/'.$todir;
  75. if(is_dir($path)){
  76. if ( move_uploaded_file( $_FILES['file']['tmp_name'], $path . basename($_FILES['file']['name'] ) ) )
  77. {
  78. echo "this doesn't work";
  79. }
  80. }
  81. else
  82. echo 'Check path '.$path;
  83.  
  84. if(isset($_POST['submit'])){
  85. //not sure if what you wrote here was valid, but most commonly it's
  86. if (isset($_FILES['file']['name']) ) // does file exist
  87. {
  88. //we'll use an easier way to find the extension
  89. $filename = $_FILES['file']['name'];
  90. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  91.  
  92. if ( in_array( $ext, $allow) ) // is this file allowed
  93. {
  94. if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
  95. {
  96. echo "file uploaded";
  97. }
  98. else
  99. {
  100. echo 'error uploading: '.$_FILES['file']['error'];
  101. }
  102.  
  103. }
  104. else
  105. {
  106. // error this file ext is not allowed
  107. echo "file not allowed";
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement