简体   繁体   中英

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 )

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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