phpbar.de logo

Mailinglisten-Archive

[php] foreach $_FILES

[php] foreach $_FILES

Sebastian Mendel lists at sebastianmendel.de
Mit Jun 29 15:10:01 CEST 2005


Sebastian Mendel wrote:
> Michael Borchers wrote:
>> ich poste 3 dateien(bilder) (<input type="file" name="image[]">)
>> und möchte sie bearbeiten, umbennen und hochladen.
>>
>> einzeln könnte ich das zb über
>> getimagesize($_FILES['image']['tmp_name'])
>> realisieren,
>>
>> aber wie mache ich am besten eine foreach schleife daraus?!
>> foreach(...)
>> {
>> 	getimagesize(...)
>> }
> 
> so, und nun noch ich ... ;-)
> 
> // anstelle von 'error' kann jedes beliebige andere
> // Attribut verwendet werden: name, type, ...
> foreach( $_FILES['image']['error'] as $key => $dumme )
> {
>     echo $_FILES['image']['error'][$key];
>     echo $_FILES['image']['type'][$key];
>     echo $_FILES['image']['size'][$key];
>     echo $_FILES['image']['name'][$key];
>     echo $_FILES['image']['tmp_name'][$key];
> }

p.s. error ist aber am praktischsten, da kann man gleich überprüfen ob
überhaupt was hochgeladen wurde oder soo


foreach( $_FILES['image']['error'] as $key => $error )
{
    switch ( $error )
    {
        case UPLOAD_ERR_OK:
            // There is no error, the file uploaded with success.
            echo $_FILES['image']['error'][$key];
            echo $_FILES['image']['type'][$key];
            echo $_FILES['image']['size'][$key];
            echo $_FILES['image']['name'][$key];
            echo $_FILES['image']['tmp_name'][$key];
            break;
        case UPLOAD_ERR_INI_SIZE:
            // The uploaded file exceeds the upload_max_filesize
            // directive in php.ini.
            break;
        case UPLOAD_ERR_FORM_SIZE:
            // The uploaded file exceeds the MAX_FILE_SIZE
            // directive that was specified in the HTML form.
            break;
        case UPLOAD_ERR_PARTIAL:
            // The uploaded file was only partially uploaded.
            break;
        case UPLOAD_ERR_NO_FILE:
            // No file was uploaded.
            break;
        case UPLOAD_ERR_NO_TMP_DIR:
            // Missing a temporary folder.
            break;
    }
}

-- 
Sebastian Mendel

www.sebastianmendel.de
www.sf.net/projects/phpdatetime | www.sf.net/projects/phptimesheet

php::bar PHP Wiki   -   Listenarchive