PHP.mk документација

Напредок на поставувањето на сесијата

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

session.upload-progress.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека session.upload-progress.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Напредок на поставувањето на сесијата

Референца за `session.upload-progress.php` со подобрена типографија и навигација.

session.upload-progress.php

Напредок на поставувањето на сесијата

Кога session.upload_progress.enabled INI опцијата е овозможена, PHP ќе може да ја следи прогресијата на прикачување на поединечни датотеки што се прикачуваат. Оваа информација не е особено корисна за самата барање за прикачување, но за време на прикачувањето на датотеката, апликацијата може да испрати POST барање до посебен крајна точка (преку XHR на пример) за да ја провери состојбата.

Прогресијата на прикачување ќе биде достапна во $_SESSION суперглобална кога се прикачува датотека, и при POST барање со променлива со исто име како session.upload_progress.name INI поставката е поставена на. Кога PHP открива такви POST барања, ќе пополни низа во $_SESSION, каде што индексот е конкатенирана вредност на session.upload_progress.prefix and session.upload_progress.name INI опции. Клучот обично се добива со читање на овие INI поставки, т.е.

<?php
$key
= ini_get("session.upload_progress.prefix") . $_POST[ini_get("session.upload_progress.name")];
var_dump($_SESSION[$key]);
?>

Исто така е можно да се cancel тековно прикачување на датотека, со поставување на $_SESSION[$key]["cancel_upload"] клуч на true. Кога се прикачуваат повеќе датотеки во исто барање, ова ќе откаже само тековно прикачување на датотека, и чекачки прикачувања на датотеки, но нема да ги отстрани успешно завршените прикачувања. Кога прикачувањето е откажано на овој начин, error клуч во $_FILES низата ќе биде поставена на UPLOAD_ERR_EXTENSION.

На session.upload_progress.freq and session.upload_progress.min_freq INI опциите контролираат колку често треба да се пресметуваат информациите за прогресијата на прикачување. Со разумна вредност за овие две поставки, дополнителниот трошок на оваа функција е речиси непостоечки.

Пример #1 Пример информации

Пример за структурата на низата за прогресија на прикачување.

<form action="upload.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
$_SESSION
["upload_progress_123"] = array(
"start_time" => 1234567890, // The request time
"content_length" => 57343257, // POST content length
"bytes_processed" => 453489, // Amount of bytes received and processed
"done" => false, // true when the POST handler has finished, successfully or not
"files" => array(
0 => array(
"field_name" => "file1", // Name of the <input/> field
// The following 3 elements equals those in $_FILES
"name" => "foo.avi",
"tmp_name" => "/tmp/phpxxxxxx",
"error" => 0,
"done" => true, // True when the POST handler has finished handling this file
"start_time" => 1234567890, // When this file has started to be processed
"bytes_processed" => 57343250, // Number of bytes received and processed for this file
),
// An other file, not finished uploading, in the same request
1 => array(
"field_name" => "file2",
"name" => "bar.avi",
"tmp_name" => NULL,
"error" => 0,
"done" => false,
"start_time" => 1234567899,
"bytes_processed" => 54554,
),
)
);
Ги ескејпува специјалните знаци во стринг за употреба во SQL изјава

Баферирањето на барањето на веб-серверот мора да биде оневозможено за ова да работи правилно, инаку PHP може да ја види датотеката прикачена само откако целосно ќе се прикачи. Сервери како Nginx се познати по баферирање на поголеми барања.

Безбедност: стандардниот сет на знаци

Информациите за прогресијата на прикачување се запишуваат во сесијата пред да се изврши било каква скрипта. Затоа, менувањето на името на сесијата преку ini_set() or session_name() ќе даде сесија без информации за прогресијата на прикачување.

Белешки од корисници 11 белешки

s.zarges
пред 13 години
Note, this feature doesn't work, when your webserver is runnig PHP via FastCGI. There will be no progress informations in the session array.
Unfortunately PHP gets the data only after the upload is completed and can't show any progress.

I hope this informations helps.
howtomakeaturn
пред 10 години
ATTENTION:

Put the upload progress session name input field BEFORE your file field in the form :

  <form action="upload.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>

If you make it after your file field, you'll waste a lot of time figuring why (just like me ...)

The following form will make you crazy and waste really a lot of time:

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

DON'T do this!
Анонимен
12 години пред
While the example in the documentation is accurate, the description is a bit off. To clarify:

PHP will populate an array in the $_SESSION, where the index is a concatenated value of the session.upload_progress.prefix and the VALUE of the POSTed session.upload_progress.name variable.
isius
пред 13 години
If you're seeing
"PHP Warning:  Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0",
then a misplaced input could be the cause. It's worth mentioning again that the hidden element MUST be before the file elements.
jortsc at gmail dot com
12 години пред
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].
nihaopaul на gmail точка com
пред 13 години
it should be noted that the hidden element come before the file element otherwise you wont get any updates.
Анонимен
12 години пред
dont't forget, that the session has to be initialized before the form is generated, otherwise the mentioned example above won't work.
raptor98 на email точка cz
пред 1 година
Warning:
Do not change session.save_path and session.name (in your application)!

The request for upload info must by POST with same value and name of your hidden input (session.upload_progress.name).

Info:
It works under IIS /FastCGI (at PHP 5.4 and PHP 8.2, other not tested).
alice на librelamp точка com
пред 9 години
There were two gotchas that got me with implementing this.

The first - if you use session_name() to change the name of sessions, this will not work. I discovered this by looking at phpinfo() and seeing that is saw a different session name.

At least in Apache, a better way to set the session is in your apache config use

php_value session.name "your custom name"

It goes within the Directory directive, might work in .htaccess - I don't know.

-=-

Secondly - in apache, don't use mod_mpm_prefork.so

That was the problem I had, that's the default in CentOS 7.

The problem is it causes Apache to wait with any additional requests until the upload is finished.

Commenting that module out and using mod_mpm_worker.so instead fixed that problem, and the progress meter worked.
ricki на rocker точка com
пред 10 години
session.upload_progress updates completely ignore custom session handlers set via  session_set_save_handler()
StrateGeyti
пред 11 години
It seems like if you send a form with the field like :

<?php echo '<input type="hidden" name="'.ini_get('session.upload_progress.name') .'" value="123" />';  ?>

without any field type "file", the server respons will be an 500 error.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.