duanba7498 2018-05-19 20:38
浏览 83
已采纳

将文件从本地文件系统上传到php服务器的问题

I am trying on upload file from local file system to a remote server using php.

I am using move_uploaded_file function but when i select a file on my local file system, it tries to find the file on remote server and hence fails. maybe i am missing something. Let's say if i am trying to upload a file from C:\Data\abc.txt. It tries to find the file on /server/abc.txt and hence fails to upload the file. Please let me know if i am missing something.

<?
    if(isset($_FILES['image'])){
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size =$_FILES['image']['size'];
        $file_tmp =$_FILES['image']['tmp_name'];
        $file_type=$_FILES['image']['type'];
        $original = $root_path .$file_name; 

        echo $_FILES['image']['tmp_name'];

        if($file_size > 100097152){
            $errors[]='File size must be less than 100 MB';
        }

        if(empty($errors)==true){
            move_uploaded_file($file_tmp, '/uploads');
            echo "Success";
        }else{
            print_r($errors);
        }
    } 
?>
<html>
   <body>

      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="image" />
         <input type="submit"/>
      </form>

   </body>
</html>
  • 写回答

3条回答 默认 最新

  • dongniaocheng3773 2018-05-19 21:07
    关注

    I dont know if I have understood you correctly, but you means with remote server your webserver? This server doesnt access your file system directly because of your browser's sandbox mode. It gets only the submitted file, the origin path doesnt matter.

    The second parameter of the function move_uploaded_file has to be the target file, not the target dictionary.

    Example:

    move_uploaded_file($file_tmp, '/uploads/' . $file_name);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献