ここでもPHPのハングを取得しています。私はこれに似た他の質問を見たことがあるが、私がなぜ偽を返すのか理解できない。テキストを送信し、電子メールでファイルを添付するフォームがあります。フォームはファイルを期待どおりに送信しますが、一度ファイルタイプの検証を開始するとエラーが発生するだけです。なぜ私の検証は常にfalseを返すのですか?in_array()が常にfalseを返すのはなぜですか? PHP
$error = False;
$file_type = $_FILES['upload']['type']; //returns the mimetype
$allowed = array("image/jpeg", "image/png", "image/gif", "application/pdf");
$total = count($_FILES['upload']['name']);
$attachments = "None";
$attachmentString = "No Attachments";
if(isset($_FILES['upload']['name']) && is_array($_FILES['upload']['name']) && count($_FILES['upload']['name']) > 0){
// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
$uploaddir = trailingslashit(realpath(__DIR__)) . 'uploads/';
wp_mkdir_p($uploaddir);
//Setup our new file path
$newFilePath = $uploaddir . basename($_FILES['upload']['name'][$i]);
if(!in_array($file_type, $allowed)) {
$error = True;
echo "Error: Only jpg, gif, png, and pdf files are allowed.<br />";
}
else
{
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
$attachments[$i] = $newFilePath;
//make string for mimetype headers in email
$attachmentString += implode($attachments[$i]) + ", ";
}
}
}
}
}
。 – Phiter
'$ file_type'は__array__です。そして、あなたがそれを印刷したら、あなたはそれを見るでしょう。しかし、今日誰がデバッグしていますか? –
in_arrayがあなたに与える前にecho $ file_typeとは何ですか?また、あなたのファイルタイプ配列 – dpp