Home PHP Libraries Data validation library Upload 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 setting Implementation and introduction of PHP file upload What is a php file? PHP file upload code PHP file upload size setting

29 Jul 2016

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 <form action="doActi

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?

06 Jul 2016

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.

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

19 Jul 2024

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 processing How to use vue and Element-plus for form validation and data processing

17 Jul 2023

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?

17 Nov 2024

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

How to implement data validation in Vue form processing How to implement data validation in Vue form processing

10 Aug 2023

How to implement data verification in Vue form processing With the continuous development of front-end technology, Vue has become one of the favorite front-end frameworks among developers. When using Vue to develop forms, data verification is a very important link. This article will introduce how to implement data validation in Vue form processing and give corresponding code examples. Data validation using the Vuelidate library Vuelidate is a lightweight Vue plug-in used to define data validation rules in Vue components. First, we need to install

See all articles