PHP code run in terminal but not working in chrome - php

I have used pdf-to-image to build my new package. and I got some problem here:
<?php
// die(echo getenv('HOME'););
require_once(__DIR__.'/vendor/autoload.php');
$fileone = realpath('demo.pdf');
$pdf = new Spatie\PdfToImage\Pdf($fileone);
$pdf->saveImage(__DIR__.'upload/');
?>
I required it into index file but I can't run this code on Chrome but it working when I run by terminal, how can I fix it?
UPDATE Adding error shared in comments:
Fatal error: Uncaught ImagickException: Failed to read the file in /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php:44 Stack trace: #0 /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php(44): Imagick->__construct('/opt/lampp/htdo...') #1 /opt/lampp/htdocs/pdf2Image/index.php(6): Spatie\PdfToImage\Pdf->__construct('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/pdf2Image/vendor/spatie/pdf-to-image/src/Pdf.php on line 44

Related

How can I solve this fatal error in my microweber/screen package that I installed in my php project?

I try to use https://packagist.org/packages/microweber/screen this PHP package, I just installed it in my project and I run the index.php file but there is an error : Any idea ?
Here is my code in my index.php file:
$url = 'https://github.com';
$screenCapture = new Capture($url);
$screenCapture->setWidth(1200);
$screenCapture->setHeight(800);
$fileLocation = 'files';
$screenCapture->save($fileLocation);
echo $screenCapture->getImageLocation();
Here is the error I had received:
[15-Feb-2023 20:51:43 UTC] PHP Fatal error: Uncaught Screen\Exceptions\PhantomJsException: sh:
/home/bloggors/capturewebpage.bloggors.com/vendor/microweber/screen/bin/phantomjs: Permission denied in
/home/bloggors/capturewebpage.bloggors.com/vendor/microweber/screen/src/Capture.php:259
Stack trace:
#0 /home/bloggors/capturewebpage.bloggors.com/controller/index.php(12): Screen\Capture->save('files')
#1 /home/bloggors/capturewebpage.bloggors.com/router.php(46): include_once('/home/bloggors/...')
#2 /home/bloggors/capturewebpage.bloggors.com/router.php(7): route('/', 'controller/inde...')
#3 /home/bloggors/capturewebpage.bloggors.com/routes.php(14): get('/', 'controller/inde...')
#4 {main}
thrown in /home/bloggors/capturewebpage.bloggors.com/vendor/microweber/screen/src/Capture.php on line 259
Any help will be of great help to me ☺

Uncaught ImagickException: UnableToOpenBlob 'uploads/Datapath.pdf': No such file or directory # error/blob.c/OpenBlob/3315

I am trying to use ImageMagick to covert the first page of pdf to image but it is not working, I tried all the solutions from Stack Overflow and some other websites such as using real path but none is working.
<?php
$image=new Imagick();
$image->readImage('uploads/Datapath.pdf[0]');
$image->writeImages('uploads/ima.jpg');
?>
This is the code but not working and is giving error
Fatal error: Uncaught ImagickException: UnableToOpenBlob 'uploads/Datapath.pdf': No such file or directory # error/blob.c/OpenBlob/3315 in F:\xampp\htdocs\Web_Engineering\webproj\try.php:3 Stack trace: #0 F:\xampp\htdocs\Web_Engineering\webproj\try.php(3): Imagick->readImage('uploads/Datapat...') #1 {main} thrown in F:\xampp\htdocs\Web_Engineering\webproj\try.php on line 3

TYPO3 v9.5: installation error Uncaught RuntimeException

I have unzipped the installation folder. When going to the install.php to start the installer I get an Fatal error: Uncaught RuntimeException.
I use XAMPP with PHP 7.2 and I go to:
http://localhost/typo3/install.php
I get following message:
Fatal error: Uncaught RuntimeException: Could not create directory "/Applications/XAMPP/xamppfiles/htdocs/typo3temp/var/log/"! in /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Utility/GeneralUtility.php:2172 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Utility/GeneralUtility.php(2140): TYPO3\CMS\Core\Utility\GeneralUtility::createDirectoryPath('/Applications/X...') #1 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(222): TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep('/Applications/X...') #2 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(193): TYPO3\CMS\Core\Log\Writer\FileWriter->createLogFile() #3 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(123): TYPO3\CMS\Core\Log\Writer\FileWriter->openLogFile() #4 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/Fil in /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 2172
Stacktrace in log file:
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Utility/GeneralUtility.php(2140): TYPO3\CMS\Core\Utility\GeneralUtility::createDirectoryPath('/Applications/X...')
#1 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(222): TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep('/Applications/X...')
#2 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(193): TYPO3\CMS\Core\Log\Writer\FileWriter->createLogFile()
#3 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/FileWriter.php(123): TYPO3\CMS\Core\Log\Writer\FileWriter->openLogFile()
#4 /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Log/Writer/Fil in /Applications/XAMPP/xamppfiles/htdocs/typo3_src/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 2172
:
No more error logs available..
The error means that php cannot write to your xampp htdocs directory, because of security restrictions of the Applications dir.
You should change your xampp configuration like in this tutorial https://pureinfotech.com/install-xampp-windows-10/

Error in creating database in MongoDB using composer

I'm trying to create a database using composer. I've demo.php as the main file and running the code on localhost.
Error message :
Fatal error: Uncaught
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable
servers found (serverSelectionTryOnce set): [socket timeout calling
ismaster on '127.0.0.1:27017'] in
C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php:201
Stack trace: #0
C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php(201):
MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
1 C:\xampp\htdocs\phpmongodb\demo.php(8): MongoDB\Database->createCollection('emplcollection') 2 {main} thrown
in C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php
on line 201
What could be the reason for this?
My code:
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client;
$companydb = $client->companydb;
$result1 = $companydb->createCollection('emplcollection');
var_dump(result1);
?>

Imagick stopped working in xampp

Installed Imagick in Xampp using this link. It was working properly but stopped working all of sudden.
Only thing I did in between, tried to configure gmail stmp setting in zend 3. Though I am not sure but it stopped working after that.
This is the error
Fatal error: Uncaught ImagickException: Imagick::__construct(): SSL
operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate
verify failed in C:\xampp\htdocs\restau\restau\public\image.php:55
Stack trace: #0 C:\xampp\htdocs\restau\restau\public\image.php(55):
Imagick->__construct('https://storage...') #1 {main} Next
ImagickException: Failed to read the file in
C:\xampp\htdocs\restau\restau\public\image.php:55 Stack trace: #0
C:\xampp\htdocs\restau\restau\public\image.php(55):
Imagick->__construct('https://storage...') #1 {main} thrown in
C:\xampp\htdocs\restau\restau\public\image.php on line 55
Edit 1
Followed this link and changed
curl.cainfo ="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"
openssl.cafile="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"
this is the error I am getting now
Fatal error: Uncaught ImagickException: Failed to read the file in C:\xampp\htdocs\restau\restau\public\image.php:55 Stack trace: #0 C:\xampp\htdocs\restau\restau\public\image.php(55): Imagick->__construct('https://storage...') #1 {main} thrown in C:\xampp\htdocs\restau\restau\public\image.php on line 55
Below is the code in which image is not getting loaded, this was working properly until few days ago.
<img src="/image.php?filename=https://storage.googleapis.com/xxxxxx/uploads_56ea606ea4685.jpg&width=380&height=255" alt="">
Thanks in advance!!
This is how I fixed this problem.
I replaced this part of code
if(filter_var($imagePath, FILTER_VALIDATE_URL)) {
$imagick = new Imagick($imagePath);
} else {
$imagick = new Imagick(getcwd().$imagePath);
}
with this
if(filter_var($imagePath, FILTER_VALIDATE_URL)) {
$tempFile = 'temp/file-'.uniqid().'.jpg';
copy($imagePath, $tempFile);
$imagick = new Imagick(getcwd().'/'.$tempFile);
unlink(getcwd().'/'.$tempFile);
} else {
$imagick = new Imagick(getcwd().$imagePath);
}

Categories