Why won't any of the PhpPresentation examples work? - phppresentation

I've done the manual install of PhpPresentation (master branch) and I'm trying to run one of the simple examples that come with the package and I can't get it running properly. I've done tons of research on how to resolve, but to no avail. See the code below along with the errors I keep receiving.
<?php
require_once 'C:/wamp/www/Classes/PHPPresentation-master/PHPPresentation-master/src/PhpPresentation/Autoloader.php';
\PhpOffice\PhpPresentation\Autoloader::register();
require_once 'C:/wamp/www/Classes/Common-master/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath('./resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new Color( 'FFE06B20' ) );
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(__DIR__ . "/sample.odp");
?>
And here's the error I'm receiving:
Fatal error: Uncaught exception 'Exception' with message 'File ./resources/phppowerpoint_logo.gif not found!' in C:\wamp\www\Classes\PHPPresentation-master\PHPPresentation-master\src\PhpPresentation\Shape\Drawing\File.php on line 34
Though when I go looking, the gif image is there...any help in understand this is appreciated.
Thanks

I too face this kind of errors most repeatedly while using PHPpresentation.
The gif image has to be placed inside the resources folder but not in the Pictures folder. Try to execute by creating a sample image in the resources folder with the same name. It worked for me

Related

passing image path from storage in Laravel failed

I have stored my images in storage/app/public/images.
and i have done the storage:link.
now i want to get a path for an image that exists in /images and i want to send it with an API.
i do the below to pass it to HTTP::attach():
$path = storage_path('images' . DIRECTORY_SEPARATOR . $new_file);
and then:
$response = Http::attach('new_file', file_get_contents($path))->post('http://localhost/imageresizer/service.php', $sizes);
when i dd($path), everything seems OK and i get the path i expect.
but there's the below error when i log::debug:
file_get_contents(C:\laragon\www\myblog\storage\images\SVoGGKjERVMYxy9qDciAhgOse9kzQsIuvBg64hjE.jpg): failed to open stream: No such file or directory
what's the problem with file_get_contents ?
If your file is in storage/app/public/images, you'll want to use:
$path = storage_path('app/public/images/' . $new_file);
NB the additional 'app/public/'.

TCPDF ERROR joomla virtuemart does not create the invoice

I use joomla 3.9.6, virtuemart 3.4.2, and tcpdf 1.0.7
When i try to view the invoice(pdf) or when i change order status to confirmed i get the TCPDF ERROR: Unable to create output file: \vmorders\invoices\invoice_190522TIXG01.pdf
i already have created the folders vmorders\invoices and gave it the proper permissions. (the site runs locally with wamp)
Php Error log
[22-May-2019 16:11:21 UTC] PHP Warning: fopen(): remote host file access not supported, file://\vmorders\invoices\invoice_190522TIXG01.pdf in C:\wamp64\www\byzantinemusic\libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php on line 1854
I think i have found the solution. Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php". At line 1850 remove code
$filename = 'file://'.$filename;
and substitute with this
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath) .$filename;
For Virtuemart 3.6.10:
Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php".
At line 1817 remove code:
$filename = 'file://'.$filename;
and replace with:
$filename = $filename;
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath)."/".$filename;

Laravel Invention Image - How to DELETE image from Storage

I created Laravel app where I wanted to upload images + resize and crop them, for that I used Invention Image
Here is my code how I'm storing images:
/*just image cropping + resizing*/
$light_image = Image::make($request->file('startup_screenshot'));
$light_image->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
});
$light_image->crop(300, 275, 0, 0);
$light_image->encode('jpg');
/*just image cropping + resizing*/
/*image storing*/
$hashed_light_image = md5($light_image->__toString());
$light_image_name = $hashed_light_image . time() . '.jpg';
Storage::put('public/images/startups-screenshots/light_previews/' . $light_image_name, $light_image->__toString());
$path_to_light_image = '/storage/images/startups-screenshots/light_previews/' . $light_image_name;
/*image storing*/
I tried to use this code to delete images but it doesn't work:
...
$startup_to_update = Startup::find($request->id);
Storage::delete($startup_to_update->screenshot);
Storage::delete($startup_to_update->screenshot_light); // pay attention
...
How Can I delete those images ?
Thank you all very much for any ideas!
I realy appreciate this ))
From what you write we can only get conjetures but well, are you sure that you are storing the correct path?, remember that Storage will be storage/app (you can check it in config->filesystem) so it would be stored in
storage/app/public/images/startups-screenshots/light_previews/ . $light_image_name
But for what i can see/think you are looking inside of
/storage/images/startups-screenshots/light_previews/' . $light_image_name
in any case if you think that what is inside $startup_to_update is the real path then you can check if it exist with
Storage::has($direction)
if it return true, then the file exist and you may have a problem with permissions.
ProTip, for these cases i use to make my own disk inside config->filesystems.php
'light_previews' => [
'driver' => 'local',
'root' => storage_path('/app/public/images/startups-screenshots/light_previews/'),
'url' => env('APP_URL').'storage/app/public/images/startups-screenshots/light_previews/',
'visibility' => 'public',
],
And then i use it like these
Storage::disk('light_previews')->put($fileName, file_get_contents($file));//store
Storage::disk('light_previews')->delete($fileName);//delete
You don't have to use intervention to delete images from storage. Intervention only acts as a image helper, not a file system helper.
use Illuminate\Support\Facades\Storage;
Storage::delete(file_path_of_image);
I fixed this, path wasn't correct,
I used this type of path to store my images: "/storage/images/startups-screenshots/light_previews/image_name.jpg" , you can see code example below:
Storage::put('public/images/startups-screenshots/light_previews/' . $light_image_name, $light_image->__toString());
As you can see I used "public/images/...." on the begining, but when I tried to delete this I couldn't because I should point path of that type "public/images/...." , not that one which I used: "/storage/images/...."
so I just changed path from "public/images/...." to "public/images/...."
and it works now
Thanks all for good ideas!

Laravel adds mysql in file path

I am facing a weird issue with Laravel 5.5. I am working on my local xampp server and trying to execute LOAD DATA INFILE query in controller function. But I am getting error PDOException (HY000)
SQLSTATE[HY000]: General error: 29 File 'D:\xampp\mysql\data\uploads\RDMST.csv' not found (Errcode: 2 "No such file or directory")
Currently my csv file is located at public/uploads folder. I tried various path settings for filename like
$fileCsv = 'uploads/RDMST.csv';
$fileCsv = public_path().'/uploads/RDMST.csv';
But I am getting same error and please notice the error path shows mysql\data in path. I am not getting from where it is appending this two folders in path. When I echo public path , it displays this:
D:\xampp\htdocs\tax\public
So, can you please help how to use path for load file without appending this "mysql\data" in path?
Any help is greatly appreciated.
Here is my complete controller function:
public function getCsv()
{
//echo public_path(); die;
//$fileCsv = public_path().'/uploads/RDMST.csv';
$fileCsv = 'uploads/RDMST.csv';
echo $query = "LOAD DATA INFILE '".$fileCsv."'
REPLACE
INTO TABLE tblreception
(year,
reception_number,
file_date,
file_time,
instrument_type,
#created_at,
#updated_at)
SET created_at=NOW(),updated_at=null";
DB::connection()->getPdo()->exec($query);
//return view('reception');
}
Can we not use csv file path?
Thanks

tcpdf with laravel 5

i want to save the output pdf file to public folder my method is
public function qrSVG()
{
$qrCodes = ['4659284fff','465928447','465928447','613271980','484016586','aaaaabbbbbccccc'];
$id = ['201596400-1','201596400-2','201596400-3','831070646','493130428','aaaaabbbb'];
PDF::SetTitle('qrcodes\test');
$i=0;
foreach(array_chunk($qrCodes, 2) as $qrCodee)
{
PDF::AddPage();
$m = 55;
$n = 30;
foreach($qrCodee as $qr)
{
QrCode::size(400);
QrCode::margin(3);
QrCode::errorCorrection('H');
QrCode::encoding('UTF-8');
QrCode::backgroundColor(255,255,255);
QrCode::color(0,0,0);
QrCode::imageTitle($id[$i]);
$svg = QrCode::generate($qr);
PDF::ImageSVG('#'.$svg, $x=$m, $y=$n, $w='100', $h='100', $link='', $align='', $palign='', $border=1, $fitonpage=false);
$i++;
$n = 150;
}
}
ob_clean();
PDF::Output('qrcodes\test.pdf');}
this code generate and open the file put don't save it when i replace the last line in my code with PDF::Output('qrcodes\test.pdf', 'F');
when i put any option with PDF::Output there is an error with F and D options the error when use F is
ErrorException in tcpdf_static.php line 2440:
fopen(): remote host file access not supported, file://qrcodes\test.pdf
and when i replace the last line with
PDF::Output($_SERVER['DOCUMENT_ROOT'] . 'qrcodes\test.pdf', 'F');
the error is
ErrorException in tcpdf.php line 2793:
Undefined property: Elibyy\TCPDF\Pdf::$h
The main reason you're getting the error about remote host file access not supported is because you need to provide the full path in the file name that you provide to the Output() method. Yeah, it's a bit annoying and it catches me out all the time!
I can't comment on the second error you're getting because I cannot get your code to run (missing methods in QrCode class). What version are you using? Also, why are you trying to create an SVG for the QR code and then adding that to the PDF? Instead of taking that approach, I would highly recommend following the approach illustrated in this example:
https://github.com/tecnickcom/TCPDF/blob/master/examples/example_050.php
As you will see in the example, you should create an instance of the TCPDF class and then work with that instance, rather than calling the static methods.

Resources