Viewed   121 times

I have a problem with PhP File Upload progress monitor at the very start.

First, here are the relevant PhP.ini settings (Directive, Local Value and Master Value):

     session.upload_progress.cleanup    On  On
     session.upload_progress.enabled    On  On
     session.upload_progress.freq   1%  1%
     session.upload_progress.min_freq   1   1   PHP_SESSION_UPLOAD_PROGRESS  PHP_SESSION_UPLOAD_PROGRESS
     session.upload_progress.prefix upload_progress_    upload_progress_

Here is the form (simplified):

     <form id="fileupload" style="position:relative;" target="iframe_fileupload" action="" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="<?echo ini_get("");?>" value="first"/>
             <input type="file" name="file_1">
            <button type="submit" >Start Submit</button>

I have JQUERY Ajax code, in the same PhP file (of course, as a JS script), as in:


    //UPDATED THIS PART after reading: http://.com/questions/19336610/delay-in-populating-session-upload-progress-data
    //POSTING the magic variable PHP_SESSION_UPLOAD_PROGRESS during status inquiry too

       var params = {PHP_SESSION_UPLOAD_PROGRESS:"first", some_var:20 };
       var data_params = jQuery.param( params );
              upload_promise = $.ajax({
                url: 'upload_status.php', 
                data: data_params,
                dataType: 'html',
                type    : 'POST',
                cache   : false 

The upload_status.php simply echoes the $_SESSION array. I also set a test session variable in the form-php to make sure that the AJAX (thru upload_status.php) picks that session variable. It does. But not a sign (no variable/index) of the upload status in the $_SESSION array! The files get uploaded. I made sure that the files are big enough so that the 5000ms is sufficient to report some intermediate status.

I have never implemented PhP file upload progress bar before so I wonder if I am missing something. Once I get one status-point in the upload, I will be able to do the rest.




There could be some issues, I have listed down few of them.

  • The web server's request buffering has to be disabled for this to work properly, else PHP may see the file upload only once fully uploaded.
  • This feature doesn't work, when your webserver is running PHP via FastCGI.
  • Don't forget, that the session has to be initialized before the form is generated, otherwise you will get no information in the session.
  • It won't work in PHP 5.3 or earlier.
  • Note that if you run that code and you print out the content of $_SESSSION[$key] you get an empty array due that session.upload_progress.cleanup is on by default and it cleans the progress information as soon as all POST data has been read. Set it to Off or 0 to see the content of $_SESSION[$key].

This can help you to track your progress bar

I hope this will help you to dig out the problem.

Monday, August 15, 2022

SOLUTION: after many hours of searching, it seems this problem was occurring when I access my website without adding the "www." before the domain. so what actually was happening is, I was logging in with sets session somewhere, that my member control doesn't recognize, so it redirects me back to, that when I login everything works Ok.

when I login from (with the www.) it logs in correctly from first attemp.

So I added a code to make sure I always have the www in the URL:

if ($_SERVER['HTTP_HOST'] == "")
   $url = "http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header("Location: $url");

and everything works well now. Hope it helps someone.

Saturday, December 17, 2022

Check out this answer for making file uploads with AJAX. It is possible, but not compatible in all browsers.

jQuery Upload Progress and AJAX file upload


Alternatively, if you want on the fly uploads, there is a cool library you can get called 'Uploadify'. It's a flash/jquery (or HTML5 now) rig that allows you to upload files on the fly. In the flash version, last time I used it... you can add in callback functions to make it do essentially anything you want.

Some clever javascript could make this work for you.

Thursday, August 4, 2022

Here is a example of what Michael is talking about.

Saturday, October 29, 2022

The include() function does not access the file via HTTP, it accesses the file through the OS's own file system. So GET variables are not counted. (as they are not part of the file name).

In layman's terms, the point of include is to "copy/paste" all the contents on one file to another on the file, so that you don't have one gigantic file, but a few smaller, more maintainable ones.

Saturday, October 15, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :