【发布时间】:2015-06-18 14:14:53
【问题描述】:
我正在使用 PHP 上传文件,但我想只允许 PDF、DOC、DOCX。 我在这里找到了一些答案,但没有一个对我有帮助。
这是我的代码:
$from = str_replace(array("\r", "\n"), '', $mail); // to prevent email injection
if ($file) {
$filename = basename($_FILES['fileupload']['name']);
$file_size = filesize($file);
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
$header = "MIME-Version: 1.0\r\n"
."From: {$name}<{$from}>\r\n"
."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
."This is a Mime.\r\n\r\n"
."--".$uid."\r\n"
."From: {$name}<{$from}>\r\n"
."Content-type:text/html; charset=UTF-8\r\n\r\n"
.$msg1."\r\n\r\n"
."--".$uid."\r\n"
."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
.$content."\r\n\r\n"
."--".$uid."--";
$msg1 = '';
} else {
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=UTF-8\r\n";
$header .= "From: <".$mail. ">" ;
}
【问题讨论】:
-
到目前为止你发现了什么,你有什么问题?
标签: php file file-upload