search
HomePHP LibrariesData validation libraryUpload is a PHP library that handles file upload and verification.
Upload is a PHP library that handles file upload and verification.
<?php
class FileInfoTest extends PHPUnit_Framework_TestCase
{
    protected $fileWithExtension;
    protected $fileWithoutExtension;
    public function setUp()
    {
        $this->fileWithExtension = new \Upload\FileInfo(dirname(__FILE__) . '/assets/foo.txt', 'foo.txt');
        $this->fileWithoutExtension = new \Upload\FileInfo(dirname(__FILE__) . '/assets/foo_wo_ext', 'foo_wo_ext');
    }
    public function testConstructor()
    {
        $this->assertAttributeEquals('foo', 'name', $this->fileWithExtension);
        $this->assertAttributeEquals('txt', 'extension', $this->fileWithExtension);
        $this->assertAttributeEquals('foo_wo_ext', 'name', $this->fileWithoutExtension);
        $this->assertAttributeEquals('', 'extension', $this->fileWithoutExtension);
    }

We know that in the process of using the language, we will definitely pay attention to the security issues in the actual development process. So, today we will introduce to you the primary measure to ensure PHP security-verification data. Validation of data is the most important habit you can adopt. And when it comes to input, it's very simple: don't trust the user. When validating data to secure PHP, remember that it's often easier to design and validate the values ​​your application allows than to protect against all unknown values.

General validation tips that apply to various types of validation data are listed below:

1. Use values ​​from the whitelist

2. Always re-validate limited options

3. Use the built-in escape function

4. Verify that the correct data type (such as a number)

The value in the white-listed value (White-listed value) is the correct value , as opposed to an invalid blacklist value (Black-listed value). The difference between the two is that typically when validating data, the list or range of possible values ​​is smaller than the list or range of invalid values, many of which may be unknown or unexpected values.


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

Implementation and introduction of PHP file upload What is a php file? PHP file upload code PHP file upload size settingImplementation and introduction of PHP file upload What is a php file? PHP file upload code PHP file upload size setting

29Jul2016

PHP file, file upload: Implementation and introduction of PHP file upload: The implementation and introduction are in the program comments. Page to submit files: (can be submitted to doAction.php, doAction1.php, doAction2.php respectively for testing) upload.php file upload

Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails?Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails?

06Jul2016

Is there a PHP open source system like piwigo that supports psd upload and generate thumbnails? After using piwigo to build a picture sharing system, I found two problems: 1. The picture is too long and thumbnails cannot be generated. 2. The psd uploaded by ftp cannot generate thumbnails.

Why is my Java HttpClient file upload to PHP failing, despite a successful request and response?Why is my Java HttpClient file upload to PHP failing, despite a successful request and response?

02Dec2024

Upload Files with Java HttpClient and PHPIn this scenario, you're attempting to upload a file to Apache with PHP using the Java HttpClient library...

Best Practices for Using Pydantic in PythonBest Practices for Using Pydantic in Python

19Jul2024

Pydantic is a Python library that simplifies data validation using type hints. It ensures data integrity and offers an easy way to create data models with automatic type checking and validation. In software applications, reliable data validation is

How to use vue and Element-plus for form validation and data processingHow to use vue and Element-plus for form validation and data processing

17Jul2023

How to use Vue and ElementPlus for form validation and data processing Introduction: In web development, form validation and data processing are very important. Vue is a popular JavaScript framework, and ElementPlus is a Vue-based UI component library. Their combination can effectively simplify the process of form validation and data processing. This article will introduce how to use Vue and ElementPlus to implement form validation and data processing, and give relevant code

Is there a reliable PHP library for email address validation?Is there a reliable PHP library for email address validation?

17Nov2024

PHP Email Address Validation Library InquiryValidating email addresses is essential to ensure data integrity. However, creating a compliant...

See all articles