Bu nasıl Anahtarı deyimi çalıştırmak için hangi durumda biliyor?

2 Cevap php

Burada bir kod formu okuyorum ve ben sorun bu kodu anlamakta yaşıyorum PHP + MySQL kitap. Bu kod bir veritabanına yüklenen bir dosyayı kontrol ilgili. (Varsa, ben bunu yazarak edildi herhangi bir yazım hatalarını affedin)

S1: nasıl yankı durumda biliyor? Tüm kod, her durumda hiçbir söz yoktur.

S2: Neden davayı 5 atlamak?! Ya da (ben davayı 1, davayı 18, davayı 2 olabilir?) Hangisini kullanmak numaraları farketmez

Bu deyim, diyebilirim ($ _FILES [''] ['error'] = 1) yerine> 0 olur? Onlar aynı şey midir?

    if($_FILES['userfile']['error']>0)
{
    echo 'Problem: ';
switch($_FILES['userfile']['error'])
{
    case 1: echo 'File exceeded upload_max_filesize';
            break;
    case 2: echo 'File exceeded max_file_size';
            break;
    case 3: echo 'File only partially uploaded';
            break;
    case 4: echo 'No file uploaded';
            break;
    case 6: echo 'Cannot upload file: no temp directory specified';
            break;
    case 7: echo 'Upload failed: Cannot write to disk';
            break;
}
exit;
}

2 Cevap

This should help:

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.

UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

UPLOAD_ERR_EXTENSION Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.

Bunun özü size yüklenen bir dosyayı ele zaman, sen ($_FILES['userfile']['error']) dosyanın durumunu görmek için hata değerini kontrol olmasıdır. Switch deyimi, sadece mevcut olabilir olası hata kodlarını kontrol ile ayırır. Bu temelde "kablolu" vardır.

$ _FILES [''] ['Error'] sadece bir sayıdır. Switch deyimi case numarasını eşleştiğini gider. Yani if(...){goto ...;} tabloların büyük bir liste gibi. Ben davayı 5 olur hiç ya farketmez ya tahmin ediyorum.