Giter Club home page Giter Club logo

Comments (2)

Ocramius avatar Ocramius commented on August 19, 2024

Once the file is moved, any kind of upload validation will obviously fail.

In practice, the "is uploaded file" validation can only be performed when validating unfiltered input.

from laminas-validator.

froschdesign avatar froschdesign commented on August 19, 2024

@diegobittencourt
Unfortunately, I cannot reproduce the problem.

This is my short test:

include_once __DIR__ . '/vendor/autoload.php';

if (count($_FILES)) {
    $config = [
        [
            'type'       => Laminas\InputFilter\FileInput::class,
            'name'       => 'image',
            'validators' => [
                [
                    'name' => Laminas\Validator\File\UploadFile::class,
                ],
                [
                    'name'    => Laminas\Validator\File\MimeType::class,
                    'options' => [
                        'mimeType' => [
                            'image/jpeg',
                            'image/png',
                        ],
                    ],
                ],
                [
                    'name' => Laminas\Validator\File\IsImage::class,
                ],
                [
                    'name'    => Laminas\Validator\File\ImageSize::class,
                    'options' => [
                        'minWidth'  => 128,
                        'minHeight' => 128,
                        'maxWidth'  => 4096,
                        'maxHeight' => 4096,
                    ],
                ],
            ],
            'filters'    => [
                [
                    'name'    => Laminas\Filter\File\RenameUpload::class,
                    'options' => [
                        'target'               => './docs',
                        'use_upload_name'      => false,
                        'use_upload_extension' => true,
                        'overwrite'            => true,
                        'randomize'            => true,
                    ],
                ],
            ],
        ],
    ];

    $inputFilter = (new Laminas\InputFilter\Factory())
        ->createInputFilter($config)
        ->setData($_FILES);

    var_dump($_FILES);
    var_dump($inputFilter->isValid());
    var_dump($inputFilter->getMessages());

    // Execute rename filter
    $inputFilter->getValues();
}
?>
<form method="post" enctype="multipart/form-data">
    <input type="file" name="image">
    <input type="submit">
</form>

@Ocramius

Once the file is moved, any kind of upload validation will obviously fail.

The input Laminas\InputFilter\FileInput::class of laminas-inputfilter runs the validators before the filters (the opposite behaviour of Laminas\InputFilter\Input::class). So everything works as expected.

from laminas-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.