[英]PHP Upload HTML file
我想通過上傳腳本將html文件上傳到服務器。
當我嘗試上傳html文件時,它說的是無效文件。 但是下面給出的其他格式也可以使用。
$allowedExts = array("html", "gif", "jpeg", "jpg", "png");
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 200000000)
提前致謝
您的代碼中未使用$allowedExts
嗎?
您可以檢查html的mime類型:
<?php
$allowedMimeTypes = explode(',', 'image/gif,image/jpeg,image/jpg,text/html'); // add more mime-types if needed
if (in_array($_FILES['file']['type'], $allowedMimeTypes) && $_FILES['file']['size'] < 200000000) {
/** ok do something **/
}
else {
/** Oooops error **/
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.