Laravel 5.3 FileNotFoundException - laravel

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)

Related

storing a file to a symlink in laravel 9

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)'

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

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 symlink and cPanel

On my Laravel website I'm using symlink to store and show the images from storage.
With
php artisan storage:link
I had created the symlink and everytime when I upload a new news article, the image is uploaded in the main Storage and with symlink it's setup to the public folder and I'm displaying the image properly.
So far so good, but when I've created a copy of the website, a problem appears...
When I've created a copy of the website with cPanels File Manager, and move to a new location, the storage symlink in the public directory has become a folder, not a symlink.
After that when I try to upload a new news article, I can see it's uploaded in the main Storage folder, but not in the public/storage, so as a result the image is not displaying. That's because it's not a symlink anymore, but now it's a folder.
I've deleted the storage folder from the public directory, with SSH I've used the command again
php artisan storage:link
and I've created a new news article and the image is displaying properly, but now all other images are gone.
Is there any command that will regenerate the paths, so all other images will be display again?
I'm using Laravel 5.5
You can solve it in another way to create a symlinkexample.php file
into your public folder and run the file path into browser.
Then Storage folder will be created into public folder. Folder path
will be public/storage with linked to your public folder.
Code below for symlinkexample.php :
<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';
?>
Try this:
In route/web.php add the following code:
Route::get('/storage', function(){
\Artisan::call('storage:link');
return "Se han vinculado las imágenes";
});
If for some reason you are using different file structure and for some reason don't have terminal access, \Artisan::call('storage:link') will fail since it won't find public path.
Route::get('cmd', function(){
$process = new Process(['ln', '[symlink-here]','[target-folder]' ]);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
});
read about Process class here

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