如何在我的网站上传文件?

时间:2013-02-21 12:49:44

标签: php file-upload upload

我在我的网站上有文件上传的问题,因为我是php的新手。请帮我解决这个问题。这是我的代码:当我尝试运行运行此代码时,它给了我错误move_uploaded_file(/ www。 g-dms.com/livelink/livelink.exe?func=ll&objId=59413694&objAction=browse&viewType=1/Lighthouse.jpg)[function.move- uploaded-file]:无法打开流:没有错误第30行的C:\ xampp \ phpMyAdmin \ filefile.php

<?php         
      $dir = "/www.g-dms.com/livelink/livelink.exe?func=ll&objId=59413694&objAction=browse&viewType=1/";
      $types = array("image/gif","image/jpeg","image/jpg","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>

2 个答案:

答案 0 :(得分:0)

这是我见过的最奇怪的目录名称。 move_uploaded_file()有两个参数。第一个是你似乎掌握的$_FILES['upload']['tmp_name'],第二个是目的地。

答案 1 :(得分:0)

目录名称不正确。此外,您需要确保dir具有写权限,使用chmod 755 dirname为其授予所需权限。