CakePHP-Proffer
CakePHP-Proffer copied to clipboard
File `` could not be copied CannotUploadFileException
$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.
What is the tmp path of the file in $_FILES['icon']['tmp_name']
? Are you using Windows?
debug($_FILES['icon']['tmp_name']
gives
/tmp/phpFVPLjq
Using Linux
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.
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'),
]
];
Hi. has someone read this?
It isn't looking in the Table class.
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
Thanks @mikidiaz sounds like it's just a version issue.
I faced the same error in cakePHP 3.5. Currently, I briefly solved by changing some codes in ProfferBehavior.php.
@shlaing Can you share the code changes you made to see if they will solve a bug?
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!
hi, i am trying to use this, but neither it is uploading file nor saving name in db also not creating folder.
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.
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 ?