php使用ereg验证文件上传的方法,
本文实例讲述了php使用ereg验证文件上传的方法。分享给大家供大家参考。具体分析如下:
ereg格式如下:
复制代码 代码如下:
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();
}
move_uploaded_file($upfile, $templetdird.'/'.$upfile_name);
@unlink($upfile);
echo("成功上传一个文件!");
exit();
}
exit();
希望本文所述对大家的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor