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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动