How to make forms-based file upload in CakePHP?

I have been doing this for a while and cannot understand. Basically, I have an add page for my model, which you can add a map from a URL or from a file download. I have all the fields and validation, but how and where can I manage the downloaded file? There must be some easy way to do this. Thanks!

+3
source share
3 answers

First, your form must be set up to upload files.

<?php echo $form->create(Model, array('type' => 'file')); ?>

This will allow any files to upload the file to your server using $form->file(field)or $form->input(field, array('type' => 'file')).

After downloading the file, you should process everything else from Model:

function beforeSave($created) {
    extract($this->data[Model][field]);
    if ($size && !$error) {
        move_uploaded_file($tmp_name, destination);
        $this->data[Model][field] = destination;
    }
    return true;
}

, , , .

+19

. MeioUploadBehavior . jrbasso Upload Plugin.

, , MeioUploadBehavior, jrbasso at github, CakePHP.

$actsAs . ( ) , . , , . .

0

Zend . : CakePHP Zend

0

Source: https://habr.com/ru/post/1715360/


All Articles