davidyell / CakePHP-Proffer

An upload plugin for CakePHP 3
MIT License
117 stars 63 forks source link

Getting the file object in the filename field instead of the filename and dir. #284

Closed sodobean closed 4 years ago

sodobean commented 4 years ago

EDIT; Formatting. Followed the configuration as in the example,

On my table model;

$this->addBehavior('Proffer.Proffer', [
            'list_logo' => [    // The name of your upload field
                'root' => 'users_uploads', // Customise the root upload folder here, or omit to use the default
                'dir' => 'list_logo_dir',   // The name of the field to store the folder
                'thumbnailSizes' => [ // Declare your thumbnails
                    'square' => [   // Define the prefix of your thumbnail
                        'w' => 200, // Width
                        'h' => 200, // Height
                        'jpeg_quality'  => 100
                    ],
                    'portrait' => [     // Define a second thumbnail
                        'w' => 100,
                        'h' => 300
                    ],
                ],
                'thumbnailMethod' => 'gd'   // Options are Imagick or Gd
            ]
        `]);

On my template;

       <?= $this->Form->Create($userList,['type' => 'file']); ?>
        <fieldset>
            <div class="row">
                <div class="col-sm">
                    <?= $this->Form->control('list_name'); ?>
                </div>
            </div>
            <div class="row">
                <div class="col-sm">
                    <?= $this->Form->control('list_descritpion'); ?>
                </div>
            </div>
            <div class="row">
                <div class="col-sm">
                    <?= $this->Html->div('h-100 p-3', $this->Html->image('logo_placeholder.svg'),['id' => 'logo_image']); ?>
                </div>
                <div class="col-sm">
                    <?= $this->Form->control('list_logo',['type' => 'file']); ?>
                </div>
            </div>
            <div class="row">
                <div class="col-sm ">
                    <?= $this->Form->control('list_home_page_content',['type' => 'textarea','id'=>'mytextarea']); ?>
                </div>
            </div>
        </fieldset>

        <?= $this->Form->button(__('Submit')) ?>
        <?= $this->Form->end() ?> 

On my table I have ; list_logo, list_logo_dir

As the fields defined to save the data. When I try to save, I keep getting the file object (the array) in the list_logo field in the request object.

‌App\Model\Entity\UserList::__set_state(array(
   '_accessible' => 
  array (
    'list_name' => true,
    'list_descritpion' => true,
    'list_logo' => true,
    'list_logo_dir' => true,
    'list_home_page_content' => true,
    'file_count' => true,
    'user' => true,
  ),
   '_fields' => 
  array (
    'id' => 'a65527c3-5995-4861-97ef-f760f1697edd',
    'user_id' => 1,
    'file_count' => 0,
    'list_name' => 'dfdsf',
    'list_descritpion' => 'sdffd',
    'list_home_page_content' => '<p>sfddsfsdfdsf</p>',
  ),
   '_original' => 
  array (
  ),
   '_hidden' => 
  array (
  ),
   '_virtual' => 
  array (
  ),
   '_dirty' => 
  array (
    'id' => true,
    'user_id' => true,
    'file_count' => true,
    'list_name' => true,
    'list_descritpion' => true,
    'list_home_page_content' => true,
  ),
   '_new' => true,
   '_errors' => 
  array (
    'list_logo' => 
    array (
      'scalar' => 'The provided value is invalid',
      'maxLength' => 'The provided value is invalid',
    ),
  ),
   '_invalid' => 
  array (
    'list_logo' => 
    Laminas\Diactoros\UploadedFile::__set_state(array(
       'clientFilename' => 'espresso-1-100x100.jpg',
       'clientMediaType' => 'image/jpeg',
       'error' => 0,
       'file' => '/tmp/php0F9USL',
       'moved' => false,
       'size' => 2951,
       'stream' => NULL,
    )),
  ),
   '_registryAlias' => 'UserLists',
))

any insight on what I may be doing wrong?