ereg(正規表達式,字符串,[匹配部分數組名]);本程序利用了ereg來驗證用戶上傳的文件類型與文件名是否是符合文件命名規則,實例代碼如下:
- 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();//開源軟件:Vevb.com
- }
- move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
- @unlink($upfile);
- echo("成功上傳一個文件!");
- exit();
- }
- exit();
新聞熱點
疑難解答