PHP pChart used with XMAPP - retrieve Stroke image from HTML - php

i am trying to create a chart in PHP through pChart 2.3 class.
My doubt is on this function:
function autoOutput(string $FileName = "output.png", int $Compression = 6, $Filters = PNG_NO_FILTER)
{
if (php_sapi_name() == "cli") {
$this->Render($FileName, $Compression, $Filters);
} else {
$this->Stroke(TRUE, $Compression, $Filters);
}
}
Html Code:
<div id="filtri">
<?php include($_SERVER['DOCUMENT_ROOT'] . "/reportingBug/generaGrafico1.php");?>
<?php include($_SERVER['DOCUMENT_ROOT'] . "/reportingBug/recuperaTempiMediLavBug.php");?>
<?php include($_SERVER['DOCUMENT_ROOT'] . "/reportingBug/recuperaTempiMediBug.php");?>
<img src="temp/example.drawBarChart.spacing.png">
</div>
Php Script:
/* Render the picture (choose the best way) */
$myPicture->autoOutput("temp/example.drawBarChart.spacing.png");
?>
If i force the code in order to follow the if branch with Render function everything is working right
because it creates a PNG image in root folder and i can retrieve it from HTML.
but it goes through the else branch, so the stroke function is called.
In the case, i have two problems:
i don't know how to retrieve the PNG from HTML
i have a problem because the browser shows following:
I tried to use a phisical image (PNG file create on the server folder) but i think it's not correct because many user will access the application concurrently.

Related

Downloading multiple images in Codeigniter using iframe

I have a website in codeigniter and I need to give an option to user to download multiple images.
Below is simplified code. Now when I run this code it generates only the first iframe and downloads only first file. What correction is required, so that it downloads both images?
downloadimages.php contains following code:
$addtest = base_url().'admin/test_multiple_downfile/img1.jpg';
echo '<iframe src="'.$addtest.'">/iframe>';
$addtester = base_url().'admin/test_multiple_downfile/img2.jpg';
echo '<iframe src="'.$addtester.'">/iframe>';
admin.php under controller folder contains following code:
public function test_multiple_downfile()
{
$this->include_all_helpers_database_session();
$id['id'] = $this->uri->segment('3');
$this->load->view("multiple_downfile",$id);
}
multiple_downfile.php contains following code:
<?php
$this->load->helper('download');
$file_data = file_get_contents(base_url()."attachments/ur136/".$id);
$file_name = $id;
force_download($file_name, $file_data);
?>
I am new to php and codeigniter, so I might be missing something obvious here.

Paste a PDF-file into another PDF with ZendPDF

Is it possible to "merge" or "paste" a PDF-file into antother PDF? Or must it be a image instead?
The PDF i want to to paste or merge, is a simple picture that is going to appear at the bottom of the finished PDF:
//Generate the "Original" PDF here..
function addReklam($reklamblad) //The PDF that should be merged into the PDF that is created above
{
//Count how many pages that has been created, and add it at the bottom of the PDF:
if($this->drawed_lines<52)
{
$this->active_page = $this->pdf->pages[2];
}
elseif($this->drawed_lines<92)
{
$this->active_page = $this->pdf->pages[3];
}
elseif($this->drawed_lines<132)
{
$this->active_page = $this->pdf->pages[4];
}
else
{
$this->active_page = $this->pdf->pages[5];
}
//$this->active_page = $this->pdf->pages[5]; // page 5 is the last
//Add it here???
}
My recommendation would be to use the Zend_Pdf::load() method to load the "Original" PDF file into a local instance of Zend_Pdf and then you can access the pages using the pages[] array as in your sample code and use the all the standard functions like drawImage() etc to make the needed modifications prior to saving the updated version.

cakephp display image from database

Since it's not a large number of images that my db will take, i'm uploading them directly to database. However, i'm having problems displaying them, i don't want to download them, i want to see them on the page. I'm trying to display with the following code but it's not working:
function display() of MyFiles Controller:
function display($id)
{
$file = $this->MyFile->findById($id);
$this->set('image',$file['MyFile']['data']);
}
MyFile Model:
<?php
class MyFile extends AppModel {
var $name = 'MyFile';
}
?>
function add() of MyFilesController
function add() {
if (!empty($this->data) &&
is_uploaded_file($this->data['MyFile']['File']['tmp_name'])) {
$fileData = fread(fopen($this->data['MyFile']['File']['tmp_name'], "r"),
$this->data['MyFile']['File']['size']);
$this->request->data['MyFile']['name'] = $this->data['MyFile']['File']['name'];
$this->request->data['MyFile']['type'] = $this->data['MyFile']['File']['type'];
$this->request->data['MyFile']['size'] = $this->data['MyFile']['File']['size'];
$this->request->data['MyFile']['data'] = $fileData;
$this->MyFile->save($this->request->data);
$this->redirect(array('controller'=>'posts','action'=>'index'));
}
}
EDIT:
display.ctp of MyFiles View
<?php
echo '<img src="/MyFilesController/display/4" />';
?>
Saving images in a database is generally not a good idea.
You are far better off (and I assume you have done this for 'security') saving the files in a folder that is not web accessible and using Media Views to render them. This way you can still keep your security checks as you are using a controller to render the image.
Cakes media views are designed for streaming files to the browser and can easily be configured for images.
2.3 has a new feature for this
If you are not doing this for security reasons just save your self the problems and put them in webroot.

dompdf not rendering images from the server but is rendering from external source

I'm trying to figure this out for the last few days now and come up with nothing.
I have dompdf working on my server and its creating the pdf fine. The only issue is its not rending the images I send to it. I have DOMPDF_ENABLE_REMOTE set to TRUE, tmp folder is writable and get_file_contents is turned on.
Now the sample that you get in the dompdf folder renders the remote images fine it just seems to be images file from my server that's causing the issue.
I've tried absolute and relative urls.
I'm running this through codeigniter, and its the beta version 0.6.0.
This is my helper:
function create_pdf($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf");
} else {
write_file("./pdf_written_files/$filename.pdf", $dompdf->output());
}
}
My controller function:
function pdf($id)
{
if($id !== NULL)
{
$this->load->helper(array('create_pdf','text'));
$result = $this->product_model->order_by('order')->get_by(array('id' => $id))? : NULL;
$collection = $this->collection_model->my_collection($result->id);
$range = $this->range_model->my_range($result->id);
$result->collection = $collection;
$result->range = $range;
$this->_data['content'] = $result;
$html = $this->load->view('created_pdf', $this->_data, TRUE);
create_pdf($html, $result->title);
}
else
{
echo 'no input found';
}
}
Your image link must use the relative path from your web folder. Example, if your web folder is in /var/www/html/myweb and your image in your CI folder is in assets/images (in the same level as application folder), you just write the relative path : assets/images/imgname.jpg.
I had the exact same problem, no images were displaying for me - background images and inline ones. I had to set DOMPDF_ENABLE_REMOTE to true in your config dompdf_config.inc.php
Just note the security risk if you have this enabled along with DOMPDF_ENABLE_PHP.
Add following lines
$dompdf = new DOMPDF();
$dompdf->set('isRemoteEnabled', true);
$dompdf->load_html($html);
if this is not working then change method from set to set_option

Unfound image in View_Helper cause multiple db query in another View_Helper

Very nasty problem, I made a very long investigation to find out what was the origin of the bug. I made an original post for this, but I deleted it to create a new fresh post. So let's start by the start. Thank you in advance for reading this until the end.
I have a View Helper Pub.php. This one display randomly an ad. $this->pub() is called in the layout.phtml and in the phtml view files. The Helper also increments the number of impression before displaying it.
Pub.php
Class My_View_Helper_Pub extends Zend_View_Helper_Abstract {
public function pub( $place, $format ) {
// Extract the active campaigns, then randomly select one
$campaigns = $model->getActiveCampaigns();
...
// Increase the number of view for this campaign (in MySQL)
$model->increasePrint($campaign->id);
// And display the banner
echo $this->generateHtml($campaign->filename);
}
public function generateHtml($filename){
// Generate the html according to the filename (image, flash, custom tag etc...)
return $code;
}
IncreasePrint()
public function increasePrint($id){
$table = $this->getTable();
$row = $table->find($id)->current();
$row->imp_made = $row->imp_made + 1;
return $row->save();
}
My layout.phtml is also simple :
<html>
<head>
<?= $this->pub(null, 'css') ?>
</head>
<body>
<?= $this->pub(null, 'big_banner' ?>
</body>
Problem : On some actions, ads in the layout are selectionned and incremented twice ! As if the helper was instancied again.
After some search, the problem seems to come from another View Helper : LogoEvent. This helper displays a logo/image by returning proper HTML code.
LogoEvent.php
class My_View_Helper_LogoEvent extends Zend_View_Helper_Abstract
{
public function logoEvent($image, $taille = null){
$image = trim($image);
if ($taille){
$width = "max-width: {$taille}px;";
} else {
$width = '';
}
if (!empty($image)){
return '<img src="/images/agenda/logos/'. $image .'" style="'. $width .'" alt="Logo" />';
} else {
return '<img src="/images/agenda/logos/no-logo.png" style="'. $width .'" alt="No Logo" />';
}
}
}
The double-incrementation happens when the file doesn't exist on my hard disk.
Really weird... I tried this :
echo $this->logoEvent( 'existing_image.jpg', '100');
// No problem, everything works fine.
echo $this->logoEvent( 'unexisting_image.jpg', '100');
// => problem.
But
echo htmlentities($this->logoEvent( 'unexisting_image.jpg', '100'));
// No problem, everything works fine.
Someone has better knowledge than me to find out what could be the problem or a way to find it...
Thank you !
I'm almost certain that your problem is from .htaccess, where, be default in ZF, is set to send all non-existing files (the -s condition) to index.php, thus your application will fire up again (possibly into the ErrorController, for 404).
Add this in .htaccess instead, see how it fits (it omits certain files to be routed to index.php):
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]

Categories