普通网友 2012-07-12 14:39
浏览 50
已采纳

uploadprogress扩展名:uploadprogress_get_info总是返回null

i want to add a progress bar to my upload code so i've installed uploadprogress extension ( actually i've downgraded my wamp server to wamp 2.0 as this one already has the extension but new versions seems to have problem with it )

here is my backend code

/////////////////// uploading

<?php


if (isset($_POST['upload'])) {
    echo 'UPLOADING . . . <br />';

    $location = './uploads';
    $new= uniqid().'.'.end(explode('.' , basename($_FILES['mailfile']['name']) ));  
    if(move_uploaded_file( $_FILES['mailfile']['tmp_name'],"$location/$new"))
       echo 'DONE !! ';
    else
       echo 'error';

}

/////////////// getting upload info

else if(isset($_GET['get_info']))
{
        if (function_exists("uploadprogress_get_info")) {

            $info = uploadprogress_get_info($_GET['get_info']);
        } else {
            $info = 'nofunc';
        }
        var_dump($info);
}

/////////////// upload form

else
{           $uploadID = substr(md5(microtime(true)), 0, 10);
    ?>

            <form enctype="multipart/form-data" action="uploadprogress.php" method="post" >
                <input type="text" name="UPLOAD_IDENTIFIER"  value="<?php echo $uploadID; ?>" id="uploadIdentifier" />
                <input id="file" name="mailfile" type="file" />
                <input type="submit" value="Send File" id="btn" name="upload" />
            </form>

    <?php
}

and this is my front html/jquery code when file is being uploaded it gets the UPLOAD_IDENTIFIER value from iframe and the sends it to the set() function which is suppose to get the upload progress via ajax calls but it always returns null

<html>
    <head>
    <script language="javascript" src="../../js/jquery.js"></script>
        <script>
        var val;
        $(function(){

            $('#progress_iframe').load(function() {
                var ifr = $(this);

              $(this)
                .contents()
                .find('#btn')
                .bind('click', function() {

                    val = ifr.contents().find('#uploadIdentifier').val();
                     set();

                    //  do stuff
                });
            });

        })


function set() { 
   $.get('uploadprogress.php' , {get_info : val} , function(data){
      data = $.trim(data);
     $('#info').html(data) ;
     if(data < 100  )
     set();
   })
  }


        </script>
    </head>
    <body>

<div>
<iframe id="progress_iframe" src="uploadprogress.php" frameborder="0">   </iframe>
<span id="info"></span>     
</div>
    </body>
</html>

so the file is being uploaded without any problem and i've tried a big file but still as the file was being uploaded the uploadprogress_get_info was null

  • 写回答

1条回答 默认 最新

  • dongyi7901 2015-04-28 06:51
    关注
    1. Check if the UploadProgress tmp directory is accessible on the server. Meaning the "uploadprogress.file.filename_template" refers to the right tmp folder in the phpinfo.

    2. You can run the following code to check this.

      <div id="status" style="border: 1px black solid;<?php
      $templateini = ini_get("uploadprogress.file.filename_template");
      $testid = "thisisjustatest";
      $template = sprintf($templateini, $testid);
      $templateerror = false;
      if ($template && $template != $templateini && @touch($template) && file_exists($template)) {
      // print '('.$templateini.' is writable. The realpath is ' . str_replace($testid,"%s",realpath($template)) .')';
      unlink($template);
      } else {
      $templateerror = true;
      }
      if (function_exists("uploadprogress_get_info")) {
      if ($templateerror) {
      print 'background-color: red;"';
      print ">Problem. ";
      if ($template == $templateini) {
      print "uploadprogress.file.filename_template ($templateini) doesn't have an %s in it for making unique temporary files. Please adjust.<br/>";
      } else {
      print "$templateini is NOT writable. <br/>Please make sure the directory exists and is writable for the webserver. <br/>
      Or adjust the ini setting 'uploadprogress.file.filename_template' to a correct path.";
      }
      } else {
      print 'background-color: green;">The uploadprogress extension is installed and initial checks show everything is good';
      }
      } else {
      ?>
      background-color: red;">The uploadprogress extension is not installed.
      <?php } ?>

      </div>

    3. If the above code gives error, point to the correct tmp directory in the php.ini file. The following line was added in the php.ini file for Xampp tmp directory on windows localhost machine. uploadprogress.file.filename_template = C:\xampp\tmp\some_name_%s.txt

    4. Now your code should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作