SplFileInfo::getSize(): stat failed for D:\xampp\tmp\php83FA.tmp - laravel-6

When sumbit thoes field, it store my public path but face this
error:SplFileInfo::getSize(): stat failed for D:\xampp\tmp\php83FA.tmp
in laravel

Laravel 6 use this code for file upload
if ($files = $request->file('image')) {
$path = $files->store('uploads/feedback');
}
$feedbackData = Feedback::create([
'name' => $request->name,
'image' => $path,
'state_country' => $request->state_country,
'feedback' => $request->feedback,
'status' => $request->status,
]);

Related

Cakephp 4 save delete auto_increment

I'm doing cakephp4 controller test with phpUnit but when I call save my id auto_increment disapear.
My table before save():
Image before save
The test:
public function testAdd(): void
{
$this->session([
'Auth' => [
'id' => 1,
'DNI_CIF' => '22175395Z',
'name' => 'Prueba',
'lastname' => 'Prueba Prueba',
'username' => 'Pruebatesting',
'password' => 'prueba',
'email' => 'prueba#gmail.com',
'phone' => '639087621',
'role' => 'admin',
'addres_id' => 1
]
]);
$this->get('animal/add');
$this->assertResponseOk();
$data=[
'id' => 1,
'name' => 'AñadirAnimal',
'image' => '',
'specie' => 'dog',
'chip' => 'no',
'sex' => 'intact_male',
'race' => 'cat',
'age' => 1,
'information' => 'Es un animal.',
'state' => 'sick',
'animal_shelter' => [
'id' => 1,
'start_date' => '2022-11-03 10:47:38',
'end_date' => '2022-11-03 10:47:38',
'user_id' => 1,
'animal_id' => 1
]
];
$this->enableCsrfToken();
$this->post('animal/add',$data);
$this->assertResponseOk();
}
The controller:
public function add()
{
$animal = $this->Animal->newEmptyEntity();
if ($this->request->is('post')) {
$animal = $this->Animal->patchEntity($animal, $this->request->getData());
if(!$animal->getErrors){
$image = $this->request->getData('image_file');
if($image !=NULL){
$name = $image->getClientFilename();
}
if( !is_dir(WWW_ROOT.'img'.DS.'animal-img') ){
mkdir(WWW_ROOT.'img'.DS.'animal-img',0775);
if($name){
$targetPath = WWW_ROOT.'img'.DS.'animal-img'.DS.$name;
$image->moveTo($targetPath);
$animal->image = 'animal-img/'.$name;
}
}
if ($this->Animal->save($animal)) {
$this->Flash->success(__('El animal se ha añadido.'));
return $this->redirect(['action' => 'index']);
}
}
$this->Flash->error(__('El animal no se ha podido añadir, por favor intentalo de nuevo'));
}
$allUsers = $this->getTableLocator()->get('User');
$user = $allUsers->find('list', ['limit' => 200])->all();
$this->set(compact('animal','user'));
}
My table after:
Image after save
The error:
1) App\Test\TestCase\Controller\AnimalControllerTest::testAdd
Possibly related to PDOException: "SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value"
…
Failed asserting that 500 is between 200 and 204.
I don't know why this is happening or how to know the reason. In the app the controller works fine. Data in the app:
Data in app
Data in test:
Data in test
I hope someone can help me, I don't know what to try anymore or how to know where the problem is...
I tried to look at the data but it doesn't apear to have any errors so I don't know where the error can be.
It was that the sql file used in the bootstrap didn't have the autoincrement value.

Laravel queue:work not behaving same as queue:listen

<?php
namespace App\Notifications;
use Illuminate\Notifications\Channels\MailChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Config;
class DynamicEmailChannel extends MailChannel
{
public function send($notifiable, Notification $notification)
{
$service = $notification->service;
$customConfig = [];
$from = [];
if ($service->sender_email && $service->sender_password) {
$customConfig = [
'transport' => 'smtp',
'host' => 'smtp.googlemail.com',
'port' => 587,
'encryption' => 'tls',
'username' => $service->sender_email,
'password' => $service->sender_password,
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => $service->sender_email,
'name' => $service->title
];
} else {
$customConfig = [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example')
];
}
Config::set('mail.mailers.smtp', $customConfig);
Config::set('mail.from', $from);
app()->forgetInstance('mail.manager');
parent::send($notifiable, $notification);
}
}
this program works when run through php artisan queue:listen but the app()->forgetInstance('mail.manager'); runs only once when run through php artisan queue:work. How do i make it behave as with queue:listen?
I am trying to send mail notifications through credentials saved in database.
If i am not wrong, if i delete the 'mail.manager' serviceInstance, it will create new one when called with latest config. it works the same way for queue:listen but not for queue:work. what am i missing, or not understanding here.
After doing some digging replacing app()->forgetInstance('mail.manager'); with Mail::purge('smtp'); solved the issue.

Mutator doesn't fire for image upload

Working on a project in Backpack for Laravel that involves uploading images, videos, etc. Starting with a simple image upload, I have a mutator in my model as follows:
public function setThumbnailAttribute($value)
{
$attribute_name = "Thumbnail_URL";
$disk = "s3";
$destination_path = "images";
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}
But it doesn't seem to fire, and whenever the file is 'uploaded' it shows a 'C:\Windows\Temp\php6803.tmp' as the location.
My field:
$this->crud->addField([
'name' => 'Thumbnail',
'label' => 'Thumbnail',
'type' => 'image',
'upload' => true,
'disk' => 's3'
]);
And my 's3' disk in filesystems.php:
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
I've double checked that the Thumbnail_URL is fillable. I'm really not sure what I'm missing.
public function setThumbnailAttribute($value)
{
$attribute_name = "Thumbnail_URL";
$disk = "s3";
$destination_path = "images";
**MISSING** $this->attributes[$attribute_name] = '....' (image path/filename)
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}

Drupal 7 - get variables from hook_theme

I tried to pass a variable from a custom module to a tpl file.
In my custom module (named example)
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photo = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example-fancybox-photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example-fancybox-photos.tpl.php" in templates folder (in theme folder)
<pre><?php print var_dump($infosPhoto); ?></pre>
The result is NULL
I did some researchs but i dont understand why the variable is still NULL.
thanks for your help !
I finally managed to get the variable from the module to the tpl !
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photos = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example_fancybox_photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example_fancybox_photos.tpl.php" in templates folder (in MODULE (example) folder)
The problems were that:
- the tpl was not named in the same way and with dashes instead of underscore
- the tpl was in the template folder of the theme and not of the module
You have passed $photos but you have array as $photo. try to change that
Hope the below code helps you.
function example_menu(){
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
function example_display_fancybox_photos($nid){
$photos = 'value from example module!';
return theme('example_fancybox_photos',array('photos' => $photos));
}
function example_theme() {
$path = drupal_get_path('module', 'example');
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
'path' => $path,
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your module directory and inside it use the below code.
<?php print $photos; ?>
or
function example_theme() {
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your theme directory and inside it place the below code
<?php print $photos; ?>

Omnipay: The source parameter is required

I am trying to integrate omnipay into a website. The firts time I wanted to create a card, I came across this problem:
Omnipay: InvalidRequestException "The source parameter is required"
Here is my code:
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('sk_test_4IHf5iPTXVaZ8SF5GDcLTrqY');
$name_arr = explode(" ", $this->req['card-name']);
$card_data = [
'firstname' => $name_arr[0],
'surname' => $name_arr[1],
'expiryMonth' => $this->req['exp-month'],
'expiryYear' => $this->req['exp-year'],
'number' => $this->req['card-number'],
'email' => $client['email'],
'cvv' => $this->req['cvv']
];
$response = $gateway->createCard($card_data)->send();
What am I missing, or doing wrong?
Thanks!
Ok, sorry, I have found the solution! Data has to be in the following format:
$card_data = ['card' =>[
'firstname' => $name_arr[0],
'surname' => $name_arr[1],
'expiryMonth' => $this->req['exp-month'],
'expiryYear' => $this->req['exp-year'],
'number' => $this->req['card-number'],
'cvv' => $this->req['cvc']
]];