user759474
user759474

Reputation: 21

Upload file form for website, seems to work but no file in directory?

This is the code.. any ideas? Directory exists and has 777 permissions...

<html>
<head>

 </head>
<body>
<div style="width:340px; border: 2px solid #fff;">
<br> <center>



<p>We only accept files with a .jpg, .gif or .jpeg extension</p>
<?php  
  //Define some variables  
      $dir = "http://www.mywebsite.com/media/uploads/"; //B?n nên thay ð?i ðý?ng d?n cho phù h?p  
    //Ki?u file, Gif, jpeg, zip ::b?n có th? s?a ð?i n?u thích  
      $types = array("image/gif","image/pjpeg","image/pjpg","application/x-zip-compressed");  

//Check to determine if the submit button has been pressed  
    if(isset($_POST['submit'])){  

//Shorten Variables  
     $tmp_name = $_FILES['upload']['tmp_name'];  
     $new_name = $_FILES['upload']['name'];  

//Check MIME Type  
    if (in_array($_FILES['upload']['type'], $types)){  

         //Move file from tmp dir to new location  

        move_uploaded_file($tmp_name,$dir . $new_name);  

        echo "<strong>{$_FILES['upload']['name']} was uploaded sucessfully, we will be touch!</strong>";                                          

    }else{  

    //Print Error Message  

     echo "<small>File <strong><em>{$_FILES['upload']['name']}</em></strong> was not uploaded</small><br />";  

    //Debug  
   $name =  $_FILES['upload']['name'];  
   $type =    $_FILES['upload']['type'];  
   $size =    $_FILES['upload']['size'];  
   $tmp =     $_FILES['upload']['name'];  

   echo "Name: $name<br/ >Type: $type<br />Size: $size<br />Tmp: $tmp";  

    }  

    }        

else{        

    echo '';  

}  
        ?>  

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">  




      <fieldset>  


          <div style="padding-left: 90px;"><input type="file" name="upload" />  </div>

</fieldset>
<br>  
<input type="submit" name="submit" value="Upload File" />  </center>
</form></div></body></html>

Upvotes: 0

Views: 250

Answers (1)

Drewdin
Drewdin

Reputation: 1762

is this the path to the folder with the images? if the scripts are located on your localhost you need to change the path, you said it has 777 permissions so im guessing your using linux hosting.

$dir = "http://www.mywebsite.com/media/uploads/";

guessing that /media/ is located in your root folder try

$dir = "./media/uploads/";

Upvotes: 1

Related Questions