Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

File `` could not be copied CannotUploadFileException #243

Open
anuj9196 opened this issue Aug 14, 2017 · 14 comments
Open

File `` could not be copied CannotUploadFileException #243

anuj9196 opened this issue Aug 14, 2017 · 14 comments
Labels

Comments

@anuj9196
Copy link

       $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.

@davidyell
Copy link
Owner

davidyell commented Aug 14, 2017

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

@anuj9196
Copy link
Author

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

gives

/tmp/phpFVPLjq

Using Linux

@davidyell
Copy link
Owner

davidyell commented Aug 14, 2017

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.

@Tomicapo
Copy link

Tomicapo commented Sep 8, 2017

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
Copy link

Hi. has someone read this?

@davidyell
Copy link
Owner

It isn't looking in the Table class.

@mikidiaz
Copy link

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

@davidyell
Copy link
Owner

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

@shlaing
Copy link

shlaing commented Oct 20, 2017

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

@davidyell
Copy link
Owner

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

@dacdam
Copy link

dacdam commented Dec 5, 2017

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!

@tinkeshwar
Copy link

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

@davidyell
Copy link
Owner

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.

@dacdam
Copy link

dacdam commented Apr 18, 2018

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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants