简体   繁体   English

uploadprogress扩展名:uploadprogress_get_info始终返回null

[英]uploadprogress extension : uploadprogress_get_info always returning 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 ) 我想在上传代码中添加进度条,因此我安装了uploadprogress扩展名(实际上,我已经将wamp服务器降级为wamp 2.0,因为该服务器已经具有扩展名,但是新版本似乎有问题)

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 / jquery代码,它从iframe获取UPLOAD_IDENTIFIER值,并将其发送到set()函数,该函数假定是通过ajax调用来获取上传进度,但始终返回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 因此文件正在上传而没有任何问题,我尝试了一个大文件,但由于文件正在上传,uploadprogress_get_info为null

  1. Check if the UploadProgress tmp directory is accessible on the server. 检查服务器上是否可以访问UploadProgress tmp目录。 Meaning the "uploadprogress.file.filename_template" refers to the right tmp folder in the phpinfo. 意思是“ uploadprogress.file.filename_template”是指phpinfo中正确的tmp文件夹。

  2. You can run the following code to check this. 您可以运行以下代码进行检查。

    <div id="status" style="border: 1px black solid;<?php <div id =“ status” style =“ border:1px黑色固体; <?php
    $templateini = ini_get("uploadprogress.file.filename_template"); $ templateini = ini_get(“ uploadprogress.file.filename_template”);
    $testid = "thisisjustatest"; $ testid =“ thisisjustatest”;
    $template = sprintf($templateini, $testid); $ template = sprintf($ templateini,$ testid);
    $templateerror = false; $ templateerror =假;
    if ($template && $template != $templateini && @touch($template) && file_exists($template)) { 如果($ template && $ template!= $ templateini && @touch($ template)&& file_exists($ template)){
    // print '('.$templateini.' is writable. The realpath is ' . str_replace($testid,"%s",realpath($template)) .')'; //打印'('。$ templateini。'是可写的。真实路径为'。str_replace($ testid,“%s”,realpath($ template))。')';;
    unlink($template); unlink($ template);
    } else { }其他{
    $templateerror = true; $ templateerror = true;
    } }
    if (function_exists("uploadprogress_get_info")) { 如果(function_exists(“ uploadprogress_get_info”)){
    if ($templateerror) { 如果($ templateerror){
    print 'background-color: red;"'; 打印'background-color:red;“';
    print ">Problem. "; 打印“>问题。”;
    if ($template == $templateini) { 如果($ template == $ templateini){
    print "uploadprogress.file.filename_template ($templateini) doesn't have an %s in it for making unique temporary files. Please adjust.<br/>"; 打印“ uploadprogress.file.filename_template($ templateini)里面没有%s来制作唯一的临时文件。请调整。<br/>”
    } else { }其他{
    print "$templateini is NOT writable. <br/>Please make sure the directory exists and is writable for the webserver. <br/> 打印“ $ templateini是不可写的。<br/>请确保该目录存在并且对于Web服务器是可写的。<br/>
    Or adjust the ini setting 'uploadprogress.file.filename_template' to a correct path."; 或者将ini设置“ uploadprogress.file.filename_template”调整为正确的路径。”
    } }
    } else { }其他{
    print 'background-color: green;">The uploadprogress extension is installed and initial checks show everything is good'; print'background-color:green;“>已经安装了uploadprogress扩展,初步检查显示一切都很好”;
    } }
    } else { }其他{
    ?> ?>
    background-color: red;">The uploadprogress extension is not installed. background-color:red;“>未安装uploadprogress扩展名。
    <?php } ?> <?php}?>

    </div> </ div>

  3. If the above code gives error, point to the correct tmp directory in the php.ini file. 如果以上代码给出错误,请指向php.ini文件中正确的tmp目录。 The following line was added in the php.ini file for Xampp tmp directory on windows localhost machine. 在Windows本地计算机上的Xampp tmp目录的php.ini文件中添加了以下行。 uploadprogress.file.filename_template = C:\\xampp\\tmp\\some_name_%s.txt uploadprogress.file.filename_template = C:\\ xampp \\ tmp \\ some_name_%s.txt

  4. Now your code should work. 现在您的代码应该可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM