storing a file to a symlink in laravel 9 - laravel

I'm trying to get an image from the web and store it locally in my 'app/library' folder using Laravel 9. After battling for an hour with get_file_contents, I finally discovered guzzler and the file is fetched properly. Now I'm trying to save it using the following command.
$stored = Storage::put(storage_path('app/library').'/'.$filename, $content)'
$stored shows as '1', which leads me to think that it's worked, but the file is not in my app/library folder. Nor can I find any file with the correct name anywhere in my project.
Is there something wrong with my command?

Run the storage:link command.
See https://laravel.com/docs/9.x/filesystem#the-public-disk

Thanks to lagbox for the answer. I was overthinking it and didn't need 'storage_path()'. The following worked.
$stored = Storage::put('library/'.$filename, $content)'

Related

how can I solve the image uploading issue in laravel on shared hosting without ssh?

i uploaded my laravel project on a shared hosting platform everything is working fine except the image upload feature probably due to the storage:link command issue.is there any alternative for the same
Depending on the output error, it maybe permission issue and ... , but again you can use manual file upload to a folder in laravel like so :
if($request->hasFile('file_input_name')){
$file = $request->file('image');
$name = md5(time()) . '.' . $file->etClientOriginalExtension();
$file->move(public_path('files'),$name);
}
before anything create a folder named files in public folder and set its permission to 755.
Good Luck.
it seems like a permission issue
your last column in the second picture is for permission separated in 3 type
owner-group-other w for write r for reading x for executing
you have to check your images folder permission to accept write permission

Storage::download working wrong in laravel 5.7

I have a file in path:
app/public/template/templateeSkillsMatrix_Config.docx
and when i use:
return response()->download(storage_path('app/public/template/eSkillsMatrix_Config.docx'));
It is working, but when i use :
return Storage::download(storage_path('app/public/template/eSkillsMatrix_Config.docx'));
It show an error:
File not found at path: E:/project/agl/nav/New folder/DKMH/storage/app/public/template/eSkillsMatrix_Config.docx
I dont know why.
I read laravel docs , but i dont understand what is parameter of it.
Please help!
Just like #apokryfos's comment ,Storage::download(..) will automatically use the base storage path so i dont need call storage_path method. I need to call it the following:
return Storage::download('public\template\eSkillsMatrix_Config.docx');
in this line, i removed storage_path method and delete app/ in path.
and it is working for me!

Laravel pdf issue: failed to open stream: No such file or directory by using barryvdh/laravel-dompdf package

I am update composer and use barryvdh/laravel-dompdf package.
the problem is when i click the button it show me error like image below:-
Is that anyway to change the folder path? or am I missing code to modify path to download the pdf file?
You need to run this command:
php artisan vendor:publish
Then, try to create a fonts directory in the storage directory.
i.e. storage/app/fonts. Also, remember to make it writable.
For maximum execution time of 30 seconds exceeded, this is not laravel related issue but it's about php configuration issue. Please see this and fix it: http://php.net/manual/en/info.configuration.php#ini.max-execution-time
You can also see this answer: https://stackoverflow.com/a/30290770/6000629
Hope this will helps you!
Try this:
$pdf = PDF::loadView('pdf/personalpdf', compact('user','result'))->setOptions(['defaultFont' => 'sans-serif']);
It worked for me, I didn't make any file/folder
Just remove the reference to css external file in your cart.placeOrder.blade
Note: This directory must exist and be writable by the webserver process.
under the config file thats what it say: therefore you should create the fonts directory inside the storage.
"font_cache" => storage_path('fonts/'),

Laravel 5.3 FileNotFoundException

I am uploading an image to local storage as
$path = $request->image->store('images');
Image gets stored in storage/app/images/name.extension
However my problem is showing this image to the user, I am getting file not found exception
I tried, asset, Storage:get, Storage::url and etc.
Any solutions?
You can create a symbolic link to the storage/app/images/ from the public directory.
ln -s storage/images public/images
Try this one
Storage::get('/images/'.$filename);
or
Storage::get('/app/images/'.$filename);
Mistake was I was storing files in storage/app/images directory instead of storage/app/public/images and finally I retrieved using
asset('storage/'.$image-name)

deleting a image file yii

can any one pls tell me how to delete an image file and directory in yii
I have tried unlink but its not working.(the path is correct but its not deleting) but getting the error No such file or directory
unlink(Yii::app()->request->baseUrl.'/uploads/'.$model->file_id.'/'.$fileModel->file_name.$fileModel->extension);
and I also need to delete a directory in yii framework.the path is
correct but its not deleting
rmdir(Yii::app()->request->baseUrl.'/uploads/'.$model->file_id);
This is not working either, but getting the error No such file or directory.
Try:
unlink(getcwd().'/uploads/'.$model->file_id.'/'.$fileModel->file_name.$fileModel->extension);
getcwd() gets the current working directory. The docs for it are here
Instead of
Yii::app()->request->baseUrl
Try
Yii::app()->basePath
I have never used Yii's earlier versions.
For Yii2: unlink(Yii::$app->basePath.'/directory_path/'.$filename);
we can use this as well
unlink($file->getFullPath());

Resources