douwen2072 2012-02-16 21:47
浏览 27
已采纳

文件上传中断

I'd like to upload large files to my server, but i would like to be able to make breaks (for example, the user must be able to shut down his computer and to continue after reboot) in the upload process.

I think i can handle the client side upload, but I don't know how to make the server side. What is the best way to make it on the server side? Is PHP able to do that ? Is PHP the most efficient?

Thanks a lot

  • 写回答

2条回答 默认 最新

  • dongxinche1264 2012-02-16 21:53
    关注

    If you manage to do the client side do post the file in chunks, you could do something like this on the server side:

        // set the path of the file you upload
        $path = $_GET['path']; 
        // set the `append` parameter to 1 if you want to append to an existing file, if you are uploading a new chunk of data
        $append = intval($_GET['append']); 
    
        // convert the path you sent via post to a physical filename on the server
        $filename = $this->convertToPhysicalPath($path);
    
        // get the temporary file
        $tmp_file = $_FILES['file']['tmp_name'];
    
        // if this is not appending
        if ($append == 0) {
            // just copy the uploaded file
            copy($tmp_file, $filename);
        } else { 
            // append file contents
            $write_handle = fopen($filename, "ab");
            $read_handle = fopen($tmp_file, "rb");
    
            $contents = fread($read_handle, filesize($tmp_file));
            fwrite($write_handle, $contents);
    
            fclose($write_handle);
            fclose($read_handle);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法