PHP Session upload progress EMPTY

旧巷老猫 提交于 2019-12-08 07:56:58

问题


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:

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


回答1:


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.




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



来源:https://stackoverflow.com/questions/23993714/php-session-upload-progress-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!