PHP Doku:: HTTP Dateiupload-Variablen - reserved.variables.files.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchSprachreferenzVordefinierte Variablen$_FILES -- $HTTP_POST_FILES [veraltet, nicht empfohlen]

Ein Service von Reinhard Neidl - Webprogrammierung.

Vordefinierte Variablen

<<$_POST -- $HTTP_POST_VARS [veraltet, nicht empfohlen]

$_REQUEST>>

$_FILES

$HTTP_POST_FILES [veraltet, nicht empfohlen]

$_FILES -- $HTTP_POST_FILES [veraltet, nicht empfohlen]HTTP Dateiupload-Variablen

Beschreibung

Ein assoziatives Array von Elementen, die vom aktuellen Skript via HTTP POST-Methode hochgeladen werden.

$HTTP_FILES_VARS enthält anfangs die selben Informationen, ist aber kein Superglobal. (Beachten Sie, dass $HTTP_FILES_VARS und $_FILES unterschiedliche Variablen sind und von PHP daher entsprechend behandelt werden.)

Changelog

Version Beschreibung
4.1.0 Einführung von $_FILES als Ablösung des bis dahin existierenden $HTTP_FILES_VARS.

Anmerkungen

Hinweis:

Dies ist eine 'Superglobale' oder automatisch globale Variable. Dies bedeutet, dass sie innerhalb des Skripts in jedem Geltungsbereich sichtbar ist. Es ist nicht nötig, sie mit global $variable bekannt zu machen, um aus Funktionen oder Methoden darauf zuzugreifen.

Siehe auch


5 BenutzerBeiträge:
- Beiträge aktualisieren...
mwgamera at gmail dot com
13.08.2009 14:40
To determine whether upload was successful you should check for error being UPLOAD_ERR_OK instead of checking the file size. When nothing is chosen to be uploaded, the key in $_FILES will still be there, but it should have error equal UPLOAD_ERR_NO_FILE.
calurion at gmail dot com
30.06.2009 1:51
For some reason when I tried to check if $_FILES['myVarName'] was empty() or !isset() or array_key_exists(), it always came back that the file was indeed in the superglobal, even when nothing was uploaded.

I wonder if this is a result of enctype="multipart/form-data".

Anyways, I solved my issue by checking to make sure that $_FILES['myVarName']['size'] > 0
Sam
22.05.2009 4:08
This is REQUIRED by the xhtml specs.
dewi at dewimorgan dot com
18.03.2009 19:35
The format of this array is (assuming your form has two input type=file fields named "file1", "file2", etc):

Array
(
    [file1] => Array
        (
            [name] => MyFile.txt (comes from the browser, so treat as tainted)
            [type] => text/plain  (not sure where it gets this from - assume the browser, so treat as tainted)
            [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
            [error] => UPLOAD_ERR_OK  (= 0)
            [size] => 123   (the size in bytes)
        )

    [file2] => Array
        (
            [name] => MyFile.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/php/php6hst32
            [error] => UPLOAD_ERR_OK
            [size] => 98174
        )
)

Last I checked (a while ago now admittedly), if you use array parameters in your forms (that is, form names ending in square brackets, like several file fields called "download[file1]", "download[file2]" etc), then the array format becomes... interesting.

Array
(
    [download] => Array
        (
            [name] => Array
                (
                    [file1] => MyFile.txt
                    [file2] => MyFile.jpg
                )

            [type] => Array
                (
                    [file1] => text/plain
                    [file2] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [file1] => /tmp/php/php1h4j1o
                    [file2] => /tmp/php/php6hst32
                )

            [error] => Array
                (
                    [file1] => UPLOAD_ERR_OK
                    [file2] => UPLOAD_ERR_OK
                )

            [size] => Array
                (
                    [file1] => 123
                    [file2] => 98174
                )
        )
)

So you'd need to access the error param of file1 as, eg $_Files['download']['error']['file1']
andrewpunch at bigfoot dot com
17.01.2009 9:16
If $_FILES is empty, even when uploading, try adding enctype="multipart/form-data" to the form tag and make sure you have file uploads turned on.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)