[PHP] Hoe krijg ik fileuploaderror constante uit dé array?

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
Op http://nl.php.net/manual/en/features.file-upload.errors.php valt te lezen dat er de volgende errornummers uit $_FILES['userfilebla']['error'] komen:
UPLOAD_ERR_OK
Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

UPLOAD_ERR_PARTIAL
Value: 3; The uploaded file was only partially uploaded.

UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.

UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
Dus als ik $_FILES['userbla']['error'] echo krijg ik daar een getal uit. Leuk, maar hoe kan ik de constante die bij deze error hoort echoen? Bijv het nummer is 4 dat ik dat dan kan herleiden naar UPLOAD_ERR_NO_FILE. Een arraytje maken is idd zo gedaan, maar ik neem aan dat deze gegevens al ergens in een array van php zitten. Via http://www.php.net/manual...get-defined-constants.php zijn alle gedefineerde constante te bekijken. Daar staan ze inderdaad tussen
-knip-
[UPLOAD_ERR_OK] => 0
[UPLOAD_ERR_INI_SIZE] => 1
[UPLOAD_ERR_FORM_SIZE] => 2
[UPLOAD_ERR_PARTIAL] => 3
[UPLOAD_ERR_NO_FILE] => 4
[UPLOAD_ERR_NO_TMP_DIR] => 6
-knip-
Aan die wijsheid kom je via
PHP:
1
2
3
<?php
print_r(get_defined_constants());
?> 


Maar nu, hoe krijg ik dan -zonder zelf een array te definiëren- aan de tekst komen ipv het getal?
Of is dat gewoon niet mogelijk?

Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

Maar nu, hoe krijg ik dan -zonder zelf een array te definiëren- aan de tekst komen ipv het getal?
Of is dat gewoon niet mogelijk?
Nee, niet zonder rare trucs. Ik zou ook niet weten waarom je dit zou willen :? Leg eens uit? :)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • pjonk
  • Registratie: November 2000
  • Laatst online: 22-09 12:22
commeric schreef op dinsdag 11 januari 2005 @ 19:25:
Maar nu, hoe krijg ik dan -zonder zelf een array te definiëren- aan de tekst komen ipv het getal?
Of is dat gewoon niet mogelijk?
Volgens mij is dat gewoon niet mogelijk. PHP kent zoveel constanten Bijvoorbeeld het getal 1 kan verwijzen naar heel veel bestaande constanten. Maar zelf een array maken valt toch wel mee? Ik zou het gewoon zo doen:
PHP:
1
2
3
4
5
6
7
8
9
$upload_error[UPLOAD_ERR_INI_SIZE] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
$upload_error[UPLOAD_ERR_FORM_SIZE] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';

// etc....

$error_code = $_FILES['user']['error'];
if ($error_code > 0) {
    echo 'Upload fout:' . $upload_error[$error_code];
}

[ Voor 10% gewijzigd door pjonk op 11-01-2005 19:47 ]

It’s nice to be important but it’s more important to be nice


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
1. Ik ben lui (oke in de tijd dat ik de op schreef had ik allang 3 arrays kunnen maken :P)
2. Ik ben benieuwd of het niet ergens uit te krijgen viel.

Acties:
  • 0 Henk 'm!

  • Skaah
  • Registratie: Juni 2001
  • Laatst online: 16-09 18:38
Maak gewoon iets zoals dit. De namen van de constanten wil je niet gebruiken, of wil je daarmee je gebruikers om het hoofd slaan?
PHP:
1
2
3
4
5
6
7
8
9
10
switch ($error)
{
    case UPLOAD_ERR_INI_SIZE:
        echo "Te groot ofzo";
        break;
    case UPLOAD_ERR_FORM_SIZE]:
        echo "Form te groot";
        break;
    // et cetera
}