无法获得文件复制进度 [英] Not able to get file copying progress

查看:100
本文介绍了无法获得文件复制进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试获取正在复制的文件的进度

Am trying to get progress of file being copied

最初,我使用以下代码发送复制文件的请求.创建文件后.我发送响应成功= 1并开始复制过程,还调用 getProgress

initially i send a request to copy the file using the below code. once the file is created. i send a response success=1 and start the copying process and also call getProgress

   $.ajax({
     url:'copyFile.php',
     type: 'post',
     dataType: 'json',
     data: {'data':someData}, 
     success: function(data) {
       if(data.success){
         progressIndex=setInterval(getProgress, 1000 );
       }
     },
     error:function(err){
      console.log(err);
     }
   });


    function getProgress(){
    $.ajax({
     url:'FileUploadProgress.php',
     type: 'post',
     dataType: 'json',
     data: {'progress':'1'}, 
     success: function(data) {
       if(!data.success){
        clearTimeout(progressIndex);
       }
     },
     error:function(err){
      console.log(err);
     }
   });
}

FileUploadProgress.php

class FileUploadProgress{
   private $filename;
   private $progress;

 public function setfileProgress($filename,$progress){
    $this->filename=$filename;
  $this->progress=$progress;
  }

function returnProgress(){
   if(empty($this->filename) || empty($this->progress)){
     echo json_encode(array('success'=>'0'));
   }else{
echo json_encode(array('success'=>1,'filename'=>$this->filename,'progress'=>$this- 
>progress));
}
}

}
  $fileuploadprogress=new FileUploadProgress;
  if($_POST['progress']){

      $fileuploadprogress->returnProgress();
 }

在复制过程中获得进度并调用函数 setfileProgress 设定进度.同样在客户端,我已经请求进度,但是wat正在获取成功= 0并且$ this-> progress为空 我在代码中缺少任何内容吗?请让我知道

while copying am getting the progress and calling the function setfileProgress to set the progress. Also in client side i have requested for progress , but wat am getting is success=0 and $this->progress is empty Am i missing anything in my code. Please let me know

推荐答案

您必须让路查询一些数据源以获取进度状态. 例如在某些数据库表或文件中的转储进度状态,等等.

You have to make way to query some datasource to get your progress status. Like dumping progress status in some DB table or file, etc..

但是PHP有一些技巧,可以在某些环境下工作.
检查以下文档:会话上传进度.

However PHP have some hacks, that works in some enviroment.
Check following docs: Session Upload Progress.

这篇关于无法获得文件复制进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆