CakePHP-Proffer icon indicating copy to clipboard operation
CakePHP-Proffer copied to clipboard

File `` could not be copied CannotUploadFileException

Open anuj9196 opened this issue 7 years ago • 14 comments

       $this->addBehavior('Proffer.Proffer', [
            'icon' => [
                'root' => WWW_ROOT . 'img',
                'dir' => 'icon_dir',
                'thumbnailSizes' => [
                    '8x8' => [
                        'w' => 8,
                        'h' => 8,
                        'jpeg_quality' => 100
                    ],
                    '16x16' => [
                        'w' => 16,
                        'h' => 16,
                        'jpeg_quality' => 100
                    ],
                    '32x32' => [
                        'w' => 32,
                        'h' => 32,
                        'jpeg_quality' => 100
                    ],
                  
                'thumbnailMethod' => 'gd'
            ]
        ]);

There is no validation I have applied.

Form

    <?= $this->Form->create($sharingNetwork, ['type' => 'file']) ?>
    <fieldset>
        <legend><?= __('Add Sharing Network') ?></legend>
        <?php
            echo $this->Form->control('title');
            echo $this->Form->control('icon', ['type' => 'file']);
            echo $this->Form->control('description');
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>

On submit, it throws an exception

File `` could not be copied. 
Proffer\Exception\CannotUploadFileException

Directory is being created in the filesystem by file is not uploading.

anuj9196 avatar Aug 14 '17 07:08 anuj9196

What is the tmp path of the file in $_FILES['icon']['tmp_name'] ? Are you using Windows?

davidyell avatar Aug 14 '17 07:08 davidyell

debug($_FILES['icon']['tmp_name']

gives

/tmp/phpFVPLjq

Using Linux

anuj9196 avatar Aug 14 '17 08:08 anuj9196

Not too sure on this one, sorry. I would suggest debugging the paths throughout the process.

As the exception is thrown in rename or move_uploaded_file fail. So the fact the filename is empty, must mean it's been lost somewhere.

davidyell avatar Aug 14 '17 09:08 davidyell

This also happens to me on Windows Xampp server.

I can see in file the ProfferBehavior.php at line 118 I don't understand the code... Why is it looking for the fields: name, type, tmp_name, etc, in the model itself? But the entity has all that data inside the "photo" field (using default config).

        $tableEntityClass = $this->_table->entityClass();

        if ($tableEntityClass !== null && $entity instanceof $tableEntityClass) {
            $uploadList = [
                [
                    'name' => $entity->get('name'),
                    'type' => $entity->get('type'),
                    'tmp_name' => $entity->get('tmp_name'),
                    'error' => $entity->get('error'),
                    'size' => $entity->get('size'),
                ]
            ];

Tomicapo avatar Sep 08 '17 16:09 Tomicapo

Hi. has someone read this?

Tomicapo avatar Sep 11 '17 20:09 Tomicapo

It isn't looking in the Table class.

davidyell avatar Sep 12 '17 08:09 davidyell

i can solve this error using this plugin, and solve this error. Try it: composer require davidyell/proffer:dev-master PD:sorry for my english

mikidiaz avatar Oct 10 '17 08:10 mikidiaz

Thanks @mikidiaz sounds like it's just a version issue.

davidyell avatar Oct 10 '17 09:10 davidyell

I faced the same error in cakePHP 3.5. Currently, I briefly solved by changing some codes in ProfferBehavior.php.

shlaing avatar Oct 20 '17 04:10 shlaing

@shlaing Can you share the code changes you made to see if they will solve a bug?

davidyell avatar Oct 20 '17 07:10 davidyell

Hello! I solved by changing the code in ProfferBehavior.php from line 120:

    if ($tableEntityClass !== null && $entity instanceof $tableEntityClass) {
        $fileInfos = $entity->get('image');
        $uploadList = [
            [
                'name' => $fileInfos['name'],
                'type' => $fileInfos['type'],
                'tmp_name' => $fileInfos['tmp_name'],
                'error' => $fileInfos['error'],
                'size' => $fileInfos['size'],
            ]
        ];
    } else {
        $uploadList = $entity->get($field);
        if (count(array_filter(array_keys($entity->get($field)), 'is_string')) > 0) {
            $uploadList = [$entity->get($field)];
        }
    }

The trick was treating the entity property as an array.

Hope this could help!

Bye!

dacdam avatar Dec 05 '17 11:12 dacdam

hi, i am trying to use this, but neither it is uploading file nor saving name in db also not creating folder.

tinkeshwar avatar Apr 18 '18 08:04 tinkeshwar

Well, that's a very broad problem @tinkeshwar. There are lots of things to check, too many to list here. I would recommend checking the documentation.

davidyell avatar Apr 18 '18 08:04 davidyell

You have to specify the "dir" field of the table:

    $this->addBehavior('Proffer.Proffer', [
        'image' => [
            'dir' => 'image_dir',
            'thumbnailSizes' => [
                'square' => ['w' => 100, 'h' => 100, 'fit' => true],
                'large' => ['w' => 250, 'h' => 250, 'fit' => true]
            ]
        ]
    ]);        

In my case, my table have the "image_dir" wich is supposed to be filled by Proffer with the directory created by the upload process.

Did you set your app like this ?

dacdam avatar Apr 18 '18 10:04 dacdam