Laravel 9 Digitalocean spaces upload file - laravel

$filename = time() . $file->getClientOriginalName();
Storage::disk('do')->put("public/images/{$directory}/{$filename}", File::get($file), 'public');
return "images/avatars/{$filename}";
I upload file there is not any error but file doesn't upload to digitalocean spaces

Related

Laravel Storage - Move Images 1 folder

I want to move all images up 1 folder after which I can remove the empty folder but I always get the error "File already exists at path: public/images"
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images');
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();
The files that I wanted to remove don't exist in the public/images directory. So why do I get the error "File already exists at path: public/images"?
This should solve your problem.
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images/'.basename($file));
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();

How to run Artisan command without a console

Someone know how to start command without console
Let me explain
After the file is downloaded successfully, you need to run the command php artisan db:seed
I tried this option but I got an error as a result
Maybe someone knows another solution to this problem
I will be very grateful
I tried this option but I got an error as a result
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');
I tried this option
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');
Artisan::call('db:seed');
And this
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts')->with(Artisan::call('db:seed'));
I think this option might work. but put artisan call above return. any lines of code after return will be ignored.
$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
Artisan::call('db:seed');// <---- this line
return redirect()->route('admin.accounts');

Unable to upload video file

I am trying to upload a video file with my controller as below
Controller
if(Request::hasFile('file1')){
echo "Yes, file";
exit;
$file = Request::file('file1');
$filename = $file->getClientOriginalName();
$path = public_path().'/uploads/';
return $file->move($path, $filename);
} else {
echo "No file";
exit;
}
When i submit my a JPG/PNG file, it echo "Yes, file" i.e the file exist but when i submit an MP4 video, the file isn't found..
What could be the issue please ? Is there a particular way of sending Mp4 to my server in Laravel ?
The issue here can be your php configuration in php.ini regarding the max allowed size of the uploaded file.
post_max_size
upload_max_filesize

Laravel 5.5 - Transfer file to S3

I have an array of filenames that looks like this
array (
'file1.jpg',
'file2.jpg',
'file3.jpg'
)
I am trying to loop through them and upload them to an S3 bucket like this..
foreach ($filenames as $filename) {
Storage::disk('s3')->put(
/* S3 */
's3foldername/' . $foldername . '/' . $filename,
/* Local Storage */
storage_path('localfolder/' . $foldername . '/' . $filename),
'public'
);
}
This isn't working for some reason, the paths all check out ok. Do I need to read the file contents first?
Storage::put() method takes either file content or a resource handle as its second argument - see the docs here: https://laravel.com/docs/5.5/filesystem#storing-files
In your case, the following should do the trick:
Storage::disk('s3')->put(
's3foldername/' . $foldername . '/' . $filename,
file_get_contents(storage_path('localfolder/' . $foldername . '/' . $filename)),
'public'
);
It's just one of the options - see the docs for more.

Laravel 4 can not upload image

I use Laravel 4.2 on wamp server.
Error:
Intervention \ Image \ Exception \ NotWritableException Can't write
image data to path (C:\wamp\www\laravel.....)
my script:
$image = Input::file('image');
$filename = date('Y-m-d-H:i:s').".".$image->getClientOriginalExtension();
$path = public_path('img/products/' . $filename);
Image::make($image->getRealPath())->resize(468, 249)->save($path);
You must enable FileInfo extension and PHP >= 5.3 (preferably 5.4) and GD or Imagick extensions for image manipulations

Resources