2

this question was asked milions of times, but I'm FIGHTING with this problem since three days, and I'm totaly confused.

I can't force PHP to save details about uploded files in $_SESSION (http://www.php.net/manual/en/session.upload-progress.php). All I can get is empty session.

The most simple example of my code:

index.php

<?php 
    session_start();
    $_SESSION['test'] = 'TEST';
?>

<form action="index.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />
    <input type="file" name="file1" />
    <input type="file" name="file2" />
    <input type="submit" />
</form>

<?php 
    print_r($_SESSION); 
?>

result - after clicking submit ;)

Array ( [test] => TEST ) // nothing more...

php -i | grep upload_progress

session.upload_progress.cleanup => Off => Off
session.upload_progress.enabled => On => On
session.upload_progress.freq => 1% => 1%
session.upload_progress.min_freq => 1 => 1
session.upload_progress.name => PHP_SESSION_UPLOAD_PROGRESS => PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix => upload_progress_ => upload_progress_

php -i | grep size

post_max_size => 2G => 2G
realpath_cache_size => 16K => 16K
upload_max_filesize => 2G => 2G
Command buffer size => 4096
Read buffer size => 32768

  • The file size of file beeing uploaded (local host): 2 x 1.5GB
  • Time of execution: 8 seconds
  • I'm using Gentoo linux with php 5.5.12, Apache 2 compiled without Fast CGI support.

Bibliography:

https://stackoverflow.com/a/21851657/1125465 - as far as I'm concerned each of these are OK in my configuration.

https://stackoverflow.com/a/13186859/1125465 - tried all the scripts, and all the versions. SESSION superglobal is empty for each one.

https://stackoverflow.com/a/11485170/1125465 - As I commented this answer... Is not an answer.

Please, help! I'm starting to loose my mind. Best regards.


UPDATE phpinfo() result screenshot:

phpinfo() screenshot

It is worth notice that files are being uploaded to tmp directory, without any troubles.

Community
  • 1
  • 1
Jacek Kowalewski
  • 2,761
  • 2
  • 23
  • 36
  • What version of PHP are you using? – RiggsFolly Jun 02 '14 at 11:59
  • PHP 5.5.12, Apache 2 compiled without Fast CGI support. (to deleted comment: PHP should init $_SESSION["upload_progress_123"] automaticaly. See link in my question: http://www.php.net/manual/en/session.upload-progress.php). Thx for interest :). – Jacek Kowalewski Jun 02 '14 at 12:00

2 Answers2

2

I think you missed the most important part of the documentation

QUOTE

When the session.upload_progress.enabled INI option is enabled, PHP will be able to track the upload progress of individual files being uploaded. This information isn't particularly useful for the actual upload request itself, but during the file upload an application can send a POST request to a separate endpoint (via XHR for example) to check the status.

This means that the session information is only available when the upload is in progress.

You therefore have to write a bit of javascript in the upload page, to fire another script on the server to query this information and return it to the javascript so that you can manipulate a slider or whatever mechanism you are using to show the user the progress of the upload. Once the upload is completed the info in the session will be scrapped.

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Thx for your answer. However, I was trying to get this $_SESSION using AJAX and every other method for "live view". To make my post clear, and short, I only pasted the smallest working example. When You will take a look at my session settings, you will notice that session.upload_progress.cleanup => Off => Off. According to manual: http://www.php.net/manual/en/session.configuration.php#ini.session.upload-progress.cleanup, it should be there even after upload. But SESSION is empty even during the upload (checked via AJAX, iframe, Jquery GET method, load method,...). Thx for your reply. – Jacek Kowalewski Jun 02 '14 at 12:12
  • PS. I think noone will downvote your answer, as it can be useful in other cases, so if you can, please do not erase it :). +1 from me, but question is still opened I think... – Jacek Kowalewski Jun 02 '14 at 12:14
  • Ok, in that case are you sure that you have edited the correct php.ini file. Have you checked using `phpinfo();`? – RiggsFolly Jun 02 '14 at 12:28
  • Yes Sir! You can check my updated question with screen. I will do everything what I can do help solving this problem. I was reading the Gentoo PHP documentation / bug reports about this one, and found nothing. Thx for your help. I think I'm just missing some detail. However I was trying with milions of different codes during last few days, and nothing worked. – Jacek Kowalewski Jun 02 '14 at 12:33
  • @JacekKowalewski did you ever figure out this problem? I'm having the same problem... – Nick Coad Oct 08 '14 at 02:14
  • Nope :(. Hovewer in the meantime there was a huge update to php and apache. I will try to update it on my gentoo, and check if it helps. Thx for visiting this problem and I will try to inform about progress in few days. BR! – Jacek Kowalewski Oct 08 '14 at 08:59
  • See here: http://stackoverflow.com/questions/26374853/upload-progress-sometimes-sessionkey-is-empty/26651874#26651874 In fact it seems to be a cache problem. Or the value is empty or the session get the value of the previous file. Struggling against that for days without any success. – Peter Oct 30 '14 at 14:15
2

I had exactly the same issue. Solution was to simply replace the handler from FastCGI to PHP-FPM. Also works on Mod PHP but it doesn't work on FastCGI even with the new PHP.

nordashi
  • 76
  • 7
  • WOW. One recompilation on Gentoo with different USE flags, and everything runs as rocket. Thx VERY much, even more as this question is so old, +1 and of course accepted. – Jacek Kowalewski Dec 10 '14 at 17:08
  • @Sebastian-Placento - This is likewise driving me crazy! I have an installation of PHP 5.4.40 / Apache 2.4.12 and I don't think FastCGI is enabled in either Apache or PHP (phpinfo(); shows Server API = Apache 2.0 Handler). I save the output of print_r($_SESSION,true); to a file on the server and it always returns array( ) ie. an empty array. I've worked 24 hours straight trying to understand this problem and still have no idea what to do so if you do have any advice for me I would greatly appreciate it! – Pancho Apr 23 '15 at 10:39
  • @Sebastijan-Placento - never mind thank you, I have resolved the issue. The problem was that the server had secure cookies enabled and I was testing using http:// so the browser was refusing to send it's cookie, causing the server to think each call was a new session. – Pancho Apr 23 '15 at 18:52