在PHP中使用CURL上傳文件時,可以通過以下步驟來驗證文件類型:
$file_path = '/path/to/uploaded/file.jpg';
$mime_type = mime_content_type($file_path);
$allowed_mime_types = array('image/jpeg', 'image/png', 'image/gif');
if (!in_array($mime_type, $allowed_mime_types)) {
// 文件類型不在允許的列表中,進行相應處理
die('Invalid file type. Only JPEG, PNG and GIF files are allowed.');
}
通過以上步驟,可以在CURL上傳文件時對文件類型進行驗證,確保只允許上傳指定類型的文件。