Font file issue using Dompdf in Laravel - laravel

I am using the Dompdf package in Laravel to download pdf's. I have the following in my web.php:
Route::get('proposal-pdf/{id}', function($id) {
$proposal = Proposal::find($id);
// $pdf = PDF::loadView('test', compact('proposal'));
$pdf = PDF::loadView('internal-admin-tools.proposal-pdf', compact('proposal'));
return $pdf->download('proposal.pdf');
return back();
});
I downloaded Dompdf using: composer require barryvdh/laravel-dompdf.
I have a view using fonts that come with Laravel. I get the following error:
fopen(C:\xampp\htdocs\HealthHub\storage\fonts/\176125b1b6dc4704cbf0390040859779.ufm): failed to open stream: No such file or directory
I added the 'fonts' directory in my 'storage' and then added the file named above. After I do that and reload, the load does not render. I think I may have to change the permissions to my 'fonts' folder and cannot find any clear answer here on how to do that. I have not done that before. I am using VSCode and XAMPP. I navigated to the 'fonts' folder in the terminal and entered: chmod mode 777. It says 'chmod' isn't recognized

Creating storage\fonts directory should fix the problem.

Related

Failed to open stream: No such file or directory using Laravel Forge

I'm using LiveWire for my Laravel project, and I'm trying to deploy using Laravel Forge but I encountered an Internal Server Error 500. I changed the .env to APP_DEBUG=true and APP_ENV=local.
Now I see the following error:
file_get_contents(/home/forge/officialmonte.co/vendor/livewire/livewire/src/../dist/manifest.json): Failed to open stream: No such file or directory (View: /home/forge/officialmonte.co/resources/views/layouts/app.blade.php) (View: /home/forge/officialmonte.co/resources/views/layouts/app.blade.php)
I thought the reason was because my project doesn't have a "dist" folder, and instead it named it as "build" folder. So I went to the file LivewireManager.php and changed the following code. My Project Folder
From this:
$manifest = json_decode(file_get_contents(__DIR__.'/../dist/manifest.json'), true);
$versionedFileName = $manifest['/livewire.js'];
To this:
$manifest = json_decode(file_get_contents(__DIR__.'/../build/manifest.json'), true);
$versionedFileName = $manifest['/livewire.js'];
But now I get this error instead:
file_get_contents(/home/forge/officialmonte.co/vendor/livewire/livewire/src/../build/manifest.json): Failed to open stream: No such file or directory (View: /home/forge/officialmonte.co/resources/views/layouts/app.blade.php) (View: /home/forge/officialmonte.co/resources/views/layouts/app.blade.php)
How can I solve this, and what is the error about? The thing that confuses me the most is that when I'm using my laptop to run the project (npm run dev), it works fine, but when I try to deploy, it breaks.

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

How to use SimplePie with Laravel

I am using Laravel 5.2. I need to get RSS feeds using SimplePie, so I install the library through composer.json and now my vendor folder contains simplepie but when i run the following code this error shows:
ErrorException in SimplePie.php line 1379: ./cache is not writeable.
Make sure you've set the correct relative or absolute path, and that
the location is server-writable.
My code in route:
Route::get('feed', function () {
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://www.thenews.com.pk/rss/2/16' //it has no images
));
$feed->init();
$itemCount=$feed->get_item_quantity();
return $itemCount;
});
Create a writeable cache folder for simplepie in the /storage/ folder (I called mine simplepie_cache).
Set the path in your feed object:
$feed->set_cache_location(storage_path() . '/simplepie_cache');
That should do the trick.
check what is saying ./cache is not writeable can't write to cache folder check permissions to this folder or try a L5 wrapper for SimplePie https://github.com/willvincent/feeds

Resources