All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
php上传获取文件相应参数-获取上传文件后缀名_php资料_编程技术

Writer: delv Article type: Programming skills(编程技巧) Time: 2013/12/29 4:40:57 Browse times: 439 Comment times: 0

php上传获取文件相应参数-获取上传文件后缀名_php资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

php上传获取文件相应参数-获取上传文件后缀名_php资料_编程技术-你的首页-uuhomepage.com以下是我上传了一个图片后显示的 $_FILES['filename']的信息
[filename] => Array
(
[name] => Winter.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php2jw7QX
[error] => 0
[size] => 105542
)
其中type是文件类型的minitype 表示方法,例如普通的HTML的类型是text/html
如果你想用扩展名的方式判断的话可以用以下代码:
#允许的文件扩展名
$allowed_types = array('jpg', 'gif', 'png');
$filename = $_FILES['filename']['name'];
#正则表达式匹配出上传文件的扩展名
preg_match('|\.(\w+)$|', $filename, $ext);
#print_r($ext);
#转化成小写
$ext = strtolower($ext[1]);
#判断是否在被允许的扩展名里
if(!in_array($ext, $allowed_types)){
die('不被允许的文件类型');
}
?>




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.