时间:2021-07-01 10:21:17 帮助过:6人阅读
if($_SERVER['REQUEST_METHOD']=='POST'){
if(is_uploaded_file($_FILES['up']['tmp_name'])){
$path='./upload/';
is_dir($path) || mkdir($path,0777,true);
$type=ltrim(strchr($_FILES['up']['type'],'/'),'/');
$fileName = time().mt_rand(0, 9999).'.'.$type;
$fullpath = $path . $fileName;
move_uploaded_file($_FILES['up']['tmp_name'], $fullpath);
}
}
规定上传文件只能是图片 如果是其它文件则不能上传 这个怎么样限制呢?
if($_SERVER['REQUEST_METHOD']=='POST'){
if(is_uploaded_file($_FILES['up']['tmp_name'])){
$path='./upload/';
is_dir($path) || mkdir($path,0777,true);
$type=ltrim(strchr($_FILES['up']['type'],'/'),'/');
$fileName = time().mt_rand(0, 9999).'.'.$type;
$fullpath = $path . $fileName;
move_uploaded_file($_FILES['up']['tmp_name'], $fullpath);
}
}
通过扩展名判断,有风险
通过MIME Types判断