PHP file upload with Ereg security authentication file name extension

Source: Internet
Author: User

The Ereg format is as follows:

The code is as follows Copy Code
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:

  code is as follows copy code
if (!is_uploaded_file ($upfile))
 {
  Echo (" You did not upload 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 uploading!") -1 ");
    exit ();
 }
  Move_uploaded_file ($upfile, $templetdird. ' /'. $upfile _name);
  @unlink ($upfile);
  Echo ("Upload a file successfully!") ");
  exit ();
 }
 exit ();

Now we just talk about verifying the file name of the upload is legitimate, later tutorials we will continue to say how to determine whether the uploaded content is safe.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.