File permission error on server - php

I Am using send grid for codeigniter. My target is send pdf mail.
An uncaught Exception was encountered
Type: Guzzle\Common\Exception\InvalidArgumentException
Message: Unable to open http://website.com/projectdemo/webusa/uploads/files/ash.pdf for reading
Filename:opt/lampp/htdocs/projectdemo/webusa/application/third_party/sendEmail/vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php
Line Number: 53
My PHP Code:-
$pdfFilePath = HOSTNAME."uploads/files/ash.pdf";
$this->sendMail($to, $subject, $message , $pdfFilePath );

You can not access a file with its HTTP path. Change it to the absolute path like below
root_directory/path/to/file/residing/ash.pdf
eg(local machine): D://my_folder/myfiles/ash.pdf
eg(live server): /public_html/myfiles/ash.pdf

When trying to post a file to a remote location, Guzzle requires that file to be local. You should look into downloading the file at http://website.com/projectdemo/webusa/uploads/files/ash.pdf and then uploading it.
If you are not keen on downloading the whole file into a temporary location and then uploading it back, one possible solution would be to use streams.
Have a look at this discussion as well:
Copy remote file using Guzzle

Try this
If inside application folder
$pdfFilePath = APPPATH."uploads/files/ash.pdf";
If Outside application folder
$pdfFilePath = base_url()."uploads/files/ash.pdf";

Related

Laravel snappy file was not created

I am trying to create pdf with Laravel snappy.
The problem is when I try to run wkhtmltopdf command in the console for example:
wkhtmltopdf http://google.com google.pdf
it works fine and generates pdf.
But when I try to generate pdf in my controller, then it throws this exception:
RuntimeException
The file
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf' was not created
(command: /usr/local/bin/wkhtmltopdf --lowquality --orientation
'landscape' --page-size 'a3'
'/tmp/knp_snappy5bb49cd6bfcf14.16728595.html'
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf').
I tried to copy command above and execute directly in console. This is what I get:
Loading pages (1/6)
Error: Failed to load http://tmp/knp_snappy5bb49cd6bfcf14.16728595.html, with network status code 3 and http status code 0 - Host tmp not found
Error: Failed loading page http:///tmp/knp_snappy5bb49cd6bfcf14.16728595.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
As I can see, it tries to fetch local file as it is remote. I couldn't find this issue so I am asking if someone can solve this or has any idea.
My environment is Ubuntu 18.04 PHP and PHP 7.2.10.
This is my code:
// app.php aliases
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
// controller code
PDF::loadView('admin.reports.annual.pdf_template', $data)
->setPaper('a3', 'landscape')
->save(
storage_path('app/annual_reports/') . $report->pdf,
true // when there is file with same name it throws file already exists so I had to set owerwrite to true
);
Also, one more thing to point out, I was using barryvdh/laravel-dompdf and everything was working fine except it cannot render charts so I'm now trying to set up snappy.
In my case the problem was that I passed null in $html to Knp\Snappy\Pdf::getOutputFromHtml($html). Under the hood it cheks if $html !== null and creates a temporary file for further PDF generating. If temporary file doesn't exist wkhtmltopdf throws error like described in question.
hmm
I think (not sure) that there are a a blocking in your application that blocks your controller from getting to the link. Or at the creating of the PDF.
It can also be your code syntax.
you can try this for html :
$pdf = new Pdf('/usr/local/bin/wkhtmltopdf');
$pdf->generateFromHtml('<h1>test</h1><p>test from test</p>', '/tmp/test-123.pdf');

Can you use ssh2_scp_recv in php to get a remote directory?

I am trying to use
ssh2_scp_recv($connection, '/remote/directory', '/local/directory');
to get a remote directory, but I am getting the error:
Warning: ssh2_scp_recv(): Unable to receive remote file in /some-php-file.php on line 2.
It works if I use ssh2_scp_recv to get a single file.
Is this function supposed to work on directories? It wasn't clear from reading the docs.
You cannot use ssh2_scp_recv to get a directory. You can, however, use scandir using ssh2.sftp:// wrapper.
http://php.net/manual/en/wrappers.ssh2.php
Check this gist for an example credit for code to the gist owner danielbwa

API logging using log4php

I have log4php working via the command line successfully but I am struggling when using it with an PHP API (via Apache).
The error I am getting is;
PHP Warning: log4php: Configuration failed. Error loading configuration file: failed
to load external entity "logging.xml"
logging.xml is in the same directory as the PHP file and is loaded via;
$configFile = "logging.xml";
Logger::configure($configFile);
Ideas please? I tried changing it to use the full URL for the file and the full local path and they result in the same error.
The same setup works via the CLI.

PHP ftp_delete can't find file

When I try to use ftp_delete() I get the error: Warning: ftp_delete(): File not found. My ftp server should be working fine, I can upload files fine to the same directory without a problem. Here is the PHP:
$fileSource = 'http://localhost/user/images/dfdf.png';
$ftpCon = ftp_connect('localhost');
ftp_login($ftpCon,'---','---');
ftp_delete($ftpCon,$fileSource);
Also when I look at the server logs I can see I get the message: 550 File not found
The url for $fileSource is the file's exact path, I went into localhost and copy/pasted it into the code, still for some reason it can't be found.
The ftp_delete function acccepts a path to the file. You are providing http://localhost/user/images/dfdf.png which contains the host (http://localhost/). I think you mean to provide /user/images/dfdf.png, which is just the path.
Example:
ftp_delete($ftpCon, '/user/images/dfdf.png');
When, for example, your FTP root is /user/, it will mean you need to provide ftp_delete with /images/dfdf.png. Thanks to #maremp.

Implement APNS in Yii framework

I am doing Push Notification Service for Apple iphone/ipad. i got the server side code from http://code.google.com/p/apns-php/. it is working well.. but i have to implement it in Yii framework.
i have googled it. and got this
https://github.com/shiki/yii-apns
Here i need to set server_certificates_bundle_sandbox.pem, and device token dynamically at run time.I am new to yii..please help me how to use this component..
i have extracted all the files in components folder,and tried the below code.
$obj=new SAPNS();
$obj->providerCertificateFilePath="provider certificate file path";
$obj->rootCertificationAuthorityFilePath="root certificate path";
$obj1=$obj->getPushProvider();
but while calling getPushProvider method,i got the following error.
include(ApnsPHP_Push.php): failed to open stream: No such file or directory
There is no such a file ApnsPHP_Push.php in ApnsPHP folder in my components folder.dont know in which part i did mistake..
the guys has already wrapped up everything in a component, so you just need to put all the things in components directory and call the desired functions.
if you look at SAPNS.php its got a public property
$providerCertificateFilePath
and that will be the file path to your PEM file and other
$rootCertificationAuthorityFilePath
for secure certificate (if any).
After giving these values you have to call getPushProvider method that will give you an object for ApnsPHP_Push from here you can call this class normally as you do without framework.

Categories