TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
  • I need to have a multiple file uploader on my site with progress for each file. I'm using session.upload_progress for this, but it's not working with Kohana. Obviously it's because of the way Sessions are handled in Kohana, but I'm not really sure what to do here. Someone else seems to have had a similar problem (http://forum.kohanaframework.org/discussion/11457/php-5-4-session-upload-progress-and-kohana-3-x/p1), but it's not clear to me what he did to fix it. Is there something I can do to have the upload_progress data put into the session variable?

  • Alternatively, save the estimated download time file size of 100 KB and send in View. Template JS:

    var upload_unit = {size: 100 * 1024, time: <?php echo $download_time ?>};
    var total_time = Math.round((file.size / upload_unit.size) * upload_unit.time);
  • That's a good idea, but PHP has built-in functionality to get the actual upload progress. It just wouldn't make sense to guess the upload progress when this exists.

  • Progress bar uses native upload_progress sends too many AJAX requests for check progress status - i think it's not soo good. My version has a minimal inaccuracy and serious performance gains.

  • I appreciate the suggestion, but all of this is already implemented (I had it working before moving the app into Kohana, but after Kohana it stopped working). If I notice performance issues I'll definitely look into the estimated time approach.

    I've made progress using the accepted answer here: http://stackoverflow.com/questions/14437406/session-upload-progress/14649575.

    The problem now is when I submit the upload form, my session gets cleared. I created a simple form and tracked the problem down. If I remove < input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="upload" > from the HTML below, the form will submit without clearing the Kohana session. If I leave it in, the session gets wiped.

    < form id="test-form" name="test-form" method="post" action="#" enctype="multipart/form-data">
        < input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="upload">
        < input type="file" name="test_file">
        < input type="submit">
    < /form>

    I'm trying to track down why this is happening, but I'm not having much luck. I've been debugging this damn upload_progress for over 10 hours today. It's really irritating, especially when just using a regular PHP session works fine. I hope the Kohana devs can update their Session handling to fix this.

    EDIT: I had to add spaces in all the HTML tags in the code above. The < code > and < pre > tags aren't working.

  • in your ajax controller use Session::instance('native')->get(..) for find UPLOAD_PROGRESS value

  • Nice thanks for that. That did help me, but there's still an issue.

    I'm watching the session file and the user session gets overwritten with the upload progress data.

    So it appears that Kohana is using 'native' as the default session adapter, and PHP is using the native session to store the upload progress, so the upload progress is overwriting the Kohana user session.

    So I guess I need to use the 'cookie' adapter to store the user session. Is it safe to use 'cookie' to store the user data as long as it's encrypted?

  • I believe I've got it. Man, where do I start...


        return array(
            'native' => array(
                'name' => ini_get('session.name'),
                'encrypted' => false,
                'lifetime' => 43200,
            'cookie' => array(
                'name' => 'session_cookie',
                'encrypted' => true,
                'lifetime' => 43200,
            'database' => array(
                'name' => 'session_database',
                'group' => 'default',
                'table' => 'sessions',

    I switched to use the database as the default for Kohana sessions, and using normal PHP sessions for my upload business.

    In the action_index controller of the upload page, I called session_start();.

    To check the upload progress, I could not use Session::instance('native'). The only way it would work was to use $_SESSION[$key].

    This now allows me to have multiple uploads simultaneously and get the status of each individual upload.

    I'm so glad that's over.

  • Nevermind. It works on my local server, not on a web server. This is freakin' frustrating.

  • Any recommendations?

  • If it's working locally but not on your server, I assume it's a server setup issue?

  • Sorry, I don't know why I said that and don't even remember doing it. I was probably very frustrated and a little drunk (I'm on vacation). Still working on this issue.

    Basically my problem is that the PHP session doesn't seem to be starting at first. When I first go to the photo upload page and upload a photo then check its progress with ajax, it says it can't find the session key for the progress. If I refresh the page, everything works after that. I'm using the database for Kohana's sessions, so session_start isn't called on its own, so in my controllers index function I had session_start, and in the controller action for checking upload progress I also had session_start(). This wasn't working until I refreshed the page, so I removed both of those and put session_start in bootstrap.php. It's the same problem. This all works fine outside of Kohana.

  • Is there any way you could just use this: http://malsup.com/jquery/form/#file-upload ?

  • i need to support older browsers that don't support XMLHttpRequest. On that site it says if the browser doesn't support it, it uses an iframe method as a fallback, which is what I'm currently using for all browsers. so i'd get into the same issue i'm having right now. i suppose i could keep all of the file uploading code outside of Kohana, but I could do that with what I currently have. i'd really like to figure out why this is happening though... it's just not easy for me to debug. thanks for your suggestion though.

  • I at least found out where the problem is happening. When I first check for the upload progress in my ajax call, the key can't be found. The second time it's found. There's a 1 second delay between when the upload form is submitted and it begins checking the upload progress, so it's not a timing issue. The session is being started in bootstrap.php, so it's also not an issue with the session not being started (session.auto_start is also set to false). I checked the session ID and even the first time (when the key is not found) it returns the correct session ID. Again, this works fine outside of Kohana. When using the database module for sessions Kohana shouldn't interfere with the native php sessions, so I'm confused as to what's causing this.

    I could continue checking the upload status even when the key isn't found, but the way to check if an upload is completed is when the key has been cleared, so there's no way to know the difference between if the key hasn't been populated yet or the upload is complete.

    So, that's where I'm at. If anyone has suggestions I'd appreciate it.

  • Got it figured out... http://stackoverflow.com/questions/19336610/delay-in-populating-session-upload-progress-data. For some reason in Kohana, I need to send session.upload_progress.name in the post to the upload progress script, not just as a hidden input in the < form >. Outside of Kohana I don't need to do this and I'm still not sure why, but it appears to be fixed now.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion