php完美的ereg验证文件上传
ereg(正规表达式,字符串,[匹配部分数组名]);本程序利用了ereg来验证用户上传的文件类型与文件名是否是符合文件命名规则,实例代码如下:
<?php if (!is_uploaded_file($upfile)) { echo ("你什么都没有上传哦!"); exit(); } else { if (!ereg(".(htm|html)$", $upfile_name)) { echo ("dedecms模板只能用 .htm 或 .html扩展名!"); exit(); } if (ereg("[/]", $upfile_name)) { echo ("模板文件名有非法字符,禁止上传!-1"); exit(); } move_uploaded_file($upfile, $templetdird . '/' . $upfile_name); @unlink($upfile); echo ("成功上传一个文件!"); exit(); } exit();
教程链接:http://www.phprm.com/scxz/fs5648.html
随意转载~但请保留教程地址★