This article illustrates how PHP uses Ereg to verify file uploads. Share to everyone for your reference. The specific analysis is as follows:
The Ereg format is as follows:
Copy Code code as follows:
Ereg (regular expression, string, [match part array name]);
Here we use the Ereg to verify that the file types uploaded by the user and file names are in accordance with the file naming rules, and the instance code is as follows:
Copy Code code as follows:
if (!is_uploaded_file ($upfile))
{
Echo ("You're not uploading anything!") ");
Exit ();
}
Else
{
if (!ereg (). ( htm|html) $ ", $upfile _name))
{
Echo ("Dedecms template can only use. htm or. html extensions!") ");
Exit ();
}
if (Ereg ("[/]", $upfile _name))
{
Echo ("Template file name has illegal characters, prohibit upload!") -1 ");
Exit ();
}
Move_uploaded_file ($upfile, $templetdird. /'. $upfile _name);
@unlink ($upfile);
Echo ("Upload a file successfully!") ");
Exit ();
}
Exit ();
I hope this article will help you with your PHP program design.