0

PHP 配列 ($_FILE[fails]) があります。タイプが「image/jpeg」または「image/jpg」の thous 名のみを出力する必要があります ...

array(5) { ["name"]=> array(4) { [0]=> string(16) "3970867_460s.jpg" [1]=> string(12) "DSCI0783.JPG" [2]=> string(8) "dump.php" [3]=> string(0) "" } 
           ["type"]=> array(4) { [0]=> string(10) "image/jpeg" [1]=> string(10) "image/jpeg" [2]=> string(24) "application/octet-stream" [3]=> string(0) "" } 
           ["tmp_name"]=> array(4) { [0]=> string(27) "C:\Windows\Temp\phpC9C9.tmp" [1]=> string(27) "C:\Windows\Temp\phpC9DA.tmp" [2]=> string(27) "C:\Windows\Temp\phpC9DB.tmp" [3]=> string(0) "" } 
           ["error"]=> array(4) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(4) } ["size"]=> array(4) { [0]=> int(101011) [1]=> int(55354) [2]=> int(12290) [3]=> int(0) } 
         }

どうやってするの?foreachで?

foreach ($_FILES["fails"] as $x => $y ) {
echo $y->....something here?
   if(($y->... == 'image/jpeg') AND (..)) {}
} 

ありがとうございました!

4

3 に答える 3

1
for ($i = 0; $i < count($_FILES['fails']['name']); $i++) {
    if ($_FILES['fails']['type'][$i] == "image/jpeg" || $_FILES['fails']['type'][$i] == "image/jpg") {
        echo "Name : " . $_FILES['fails']['name'][$i];
        echo "Type : " . $_FILES['fails']['type'][$i];
    }
}

これにより、配列内のすべての image/jpg または image/jpeg の名前とタイプがエコーされます。

于 2012-04-26T09:42:29.620 に答える
0

それを試してみてください:

$output = array();
foreach ($_FILES["fails"]['type'] as $k => $type ) {
    if($type == 'image/jpeg' || $type == 'image/jpg')
        $output[] = $_FILES["fails"]['name'][$k];
}
于 2012-04-26T09:41:01.213 に答える
0

試す

$allowTypes = array (
        "image/jpeg",
        "image/jpg" 
); // Ad More to list
$_FILE ['fails'] = array ();
foreach ( $_FILES ['image'] ['tmp_name'] as $key => $val ) {
    $fileName = $_FILES ['image'] ['name'] [$key];
    $fileType = $_FILES ['image'] ['type'] [$key];
    if ($_FILES ["image"] ["error"] [$key] != UPLOAD_ERR_OK) {
        $_FILE ['fails'] [] = $fileName;
        continue;
    }

    if (! in_array ( $fileType, $allowTypes )) {
        $_FILE ['fails'] [] = $fileName;
        continue;
    }
}
于 2012-04-26T09:49:53.393 に答える