如果我有以下关联数组:
$fields = [ //store empty fields
'name' => $_POST['name'],
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'location' => $_POST['location'],
'proposal' => $_POST['proposal'] //--------------> proposal = attachment file
];
如何将它们用于$_FILES["attachment"]["name"]
?
我的计划是检查提案是pdf,docx还是.doc
这是我到目前为止所做的:
if(!empty($_FILES[$fields['proposal']]['name']) ){
//variables
$fileName = $_FILES[$fields['proposal']]['name'];
$tempName = $_FILES[$fields['proposal']]['tmp_name'];
$fileType = $_FILES[$fields['proposal']]['type'];
//get the extension of the file
$base = basename($fileName);
$extension = substr($base, strlen($base)-4, strlen($base));
//only these file types will be allowed
$allowedExtension = array(".doc", ".pdf", "docx");
//check that this file type is allowed
if (in_array($extension, $allowedExtension)) {
}else {
$errors['proposal'] = 'You can only upload pdf files';
}
}