Php uses ereg to verify File Upload

Source: Internet
Author: User
Tags ereg
This article mainly introduces how php uses ereg to verify File Upload. It is a simple and practical Regular Expression verification technique and has some reference value. If you need it, you can refer

This article mainly introduces how php uses ereg to verify File Upload. It is a simple and practical Regular Expression verification technique and has some reference value. If you need it, you can refer

This example describes how php uses ereg to verify file upload. Share it with you for your reference. The specific analysis is as follows:

The ereg format is as follows:

The Code is as follows:

Ereg (Regular Expression, String, [matching partial array names]);


Here, ereg is used to verify whether the file type and file name uploaded by the user comply with the file naming rules. The instance code is as follows:

The Code is as follows:

If (! Is_uploaded_file ($ upfile ))
{
Echo ("You have not uploaded anything! ");
Exit ();
}
Else
{
If (! Ereg (". (htm | html) $", $ upfile_name ))
{
Echo ("dedecms template can only use. htm or. html extension! ");
Exit ();
}
If (ereg ("[/]", $ upfile_name ))
{
Echo ("the template file name contains invalid characters. Upload prohibited! -1 ");
Exit ();
}
Move_uploaded_file ($ upfile, $ templetdird. '/'. $ upfile_name );
@ Unlink ($ upfile );
Echo ("a file is uploaded successfully! ");
Exit ();
}
Exit ();

I hope this article will help you with PHP programming.

,

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.