It took me 12 hours still no improvement. I try displaying different images from my computer stored in the server and the result was successful. however when displaying the reports pie graph, it wont read every time the system tries to convert to pdf. It gives a blank pdf file. On the other hand, I can view the pie graph I created by using echo''; in the reports.php. I used the same concept in dompdf file but its not working.
DOMPDF
<html>
<head>
<title></title>
</head>
<body>
<?php echo'<img src="reports-display.php"/>';?>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
JPGRAPH Drawing
<?php
require('dbcon.php');
require_once('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_pie.php');
require_once ('jpgraph/src/jpgraph_pie3d.php');
//LEGEND
//YELLOW=LIVE BLUE=WAITING GREEN=DONE
//sql query for live
$live = mysql_query("Select count(*) as count1 from tbl_display_ads where status LIKE '%Live%'") or die(mysql_error());
//sql query for waiting
$waiting = mysql_query("Select count(*) as count2 from tbl_display_ads where status LIKE '%Waiting%'") or die(mysql_error());
//sql query for done/posted advertisement
$done = mysql_query("Select count(*) as count3 from tbl_display_ads where status LIKE '%Done%'") or die(mysql_error());
//While loop for live
while($resultlive = mysql_fetch_array($live))
{
$totallive = $resultlive['count1'];
}
//While loop for waiting
while($resultwaiting = mysql_fetch_array($waiting))
{
$totalwaiting = $resultwaiting['count2'];
}
//While loop for done
while($resultdone = mysql_fetch_array($done))
{
$totaldone = $resultdone['count3'];
}
// Some data
$data = array($totallive,$totalwaiting,$totaldone);
// Create the Pie Graph.
$graph = new PieGraph(500,450);
$theme_class= new VividTheme;
$graph->SetTheme($theme_class);
// Set A title for the plot
$graph->title->Set("Figure 1.1: Totality of Display Advertisement");
// Create
$p1 = new PiePlot3D($data);
$p1->SetCenter(0.5,0.55);
$p1->SetLegends(array("Live","Waiting","Done"));
$graph->legend->SetPos(0.5,0.100,'center','bottom');
$graph->Add($p1);
$p1->ShowBorder();
$p1->SetColor('black');
$p1->ExplodeSlice(1);
$graph->Stroke();
// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Stroke image to a file and browser
// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();
?>
I finally found out the solution. in the report-display.php I set the extension name of the graph to .png and save to the directory folder for reports.
DEFINE("DEFAULT_GFORMAT","auto");
$graph->img->SetImgFormat("png");
if(file_exists("Reports/reports-display.png")) unlink("Reports/reports-display.png");
$graph->Stroke("Reports/reports-display.png");
The problem is that you're essentially asking dompdf to grab an image file called "reports-display.php" from the local filesystem. When you use $dompdf->load_html() dompdf has no idea where the content arrives from. Any resource references in the HTML that lack a full URL are pulled in via the local filesystem. Since dompdf does not parse the PHP the source will be read in, which is obviously not a valid image document.
You're found a valid solution in saving the file locally. There are two other possibilities:
1) Point to the jpgraph script through your web server.
<html>
<head>
<title></title>
</head>
<body>
<img src="http://example.com/reports-display.php"/>
</body>
</html>
2) Capture the jpgraph output and insert into the document as a data-uri.
<html>
<head>
<title></title>
</head>
<body>
<img src="data:image/png;base64,<?php echo base64_encode(include_once('reports-display.php');?>"/>
</body>
</html>
With this method reports-deplay.php would have to be updated to return the image rather than stream it. Something like:
$graph = new PieGraph(500,450);
// snip steps that generate the content
return $graph->Stroke();
Related
I'm working on a store application in PHP and am having trouble displaying stored on MySQL database. I'm storing the images as medium BLOB type and I'm confident that the images are properly formatted during and after being uploaded to the database. (I can download the images from the database directly and view them as jpeg images).
But if I try to display my images in the web page, I am getting the broken image icon. The only way I've been able to get the picture to display from sql is by using base64 encoding, but that's not the method I want to use.
Here is my code. It fetches all the products from the database and displays their id, description, and image in a table row.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Image Test</title>
<body>
<?php
include("mylibrary/login.php");
login();
$query = "SELECT prodid, description FROM products";
$result = mysql_query($query) or die(mysql_error());
echo "<table width=\"50%\" cellpadding=\"1\" border=\"1\">\n";
echo "<tr><td>Product ID</td><td>Description</td><td>Image</td></tr>\n";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$prodid = $row['prodid'];
$description = $row['description'];
echo "<tr><td>$prodid</td><td>$description</td>\n";
echo "<td><img src=\"showimage.php?id=$prodid\" width=\"80\" height=\"60\"></td></tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
This is the showimage.php code. The showimage.php file is only showing a broken image. I've looked at the raw data of the images and they're all formatted correctly. :
<?php
//header('Content-Type: image/jpeg');
$prodid = $_GET['id'];
$con = mysql_connect("localhost", "test", "test") or die('');
mysql_select_db("store", $con);
$query = "SELECT picture from products WHERE prodid=$prodid";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$picture = $row['picture'];
header("Content-type: image/jpeg");
echo $picture;
?>
I'd really appreciate help in understanding why this code isn't working. I've read numerous articles on this site and from google searches and they all say that this code should work.
As a side note, I don't want to use the base64 encoding method because I'm taking a class and this is the method that we're using (I'm also the only person who is having this problem).
Generally, the code looks almost okay. The problem with pictures is, it has to be exactly correct, otherwise it cannot be correctly displayed. Try the following things:
Use "Content-Type: image/jpeg instead of "Content-type: image/jpeg"
Remove the closing tags ?> in showimage.php - if there is a space after the closing tags, that could be your problem. You should never use closing tags for PHP-only files.
If that does not help, remove the header for the content type and have a look at what is actually returned to you by calling the picture url and compare the data to the original image. That way you can confirm that the picture data is correct or what the differences are.
I want to export fusionchart to images or pdf , what should I add? without using a third party
<?php
*//koneksi database*
include "config/koneksi.php";
error_reporting(E_ALL ^ (E_NOTICE | E_DEPRECATED));
include "config/koneksi.php";
include("config/class/FusionCharts_Gen.php");
$pencarian=$_POST['pencarian'];
$bulan=$_POST['bulan'];
$barang_aset=$_POST['barang_aset'];
?>
<html>
<head>
<title>First Chart Using FusionCharts PHP Class</title>
<script language='javascript' src='assets/js/FusionCharts.js'></script>
</head>
<body>
<?php
# Include FusionCharts PHP Class
# Create object for Column 3D chart
$FC = new FusionCharts("column3d","900","450");
# Setting Relative Path of chart swf file.
$FC->setSwfPath("Charts/");
# Store chart attributes in a variable
$strParam="caption=Grafik Jumlah Inventaris dan Aset Berdasarkan Kategori";
# Set chart attributes
$FC->setChartParams($strParam);
$kategori = mysql_query("SELECT id_kategori, nama_kategori FROM kategori");
//$tracking = mysql_query("SELECT Nama_Karyawan FROM master_karyawan WHERE Kode_Nama_Cabang='SRJ' AND Category_Tracking='sales'");
while ($r_kat = mysql_fetch_array($kategori)){
$id_kat = $r_kat['id_kategori'];
$kat = $r_kat['nama_kategori'];
$counter1 = 0;`enter code here`
**What do I need to add to add exportEnabled in this fusionchart**
//$total = mysql_num_rows(mysql_query("SELECT IdKat,TglTerjual FROM penjualan_buku WHERE IdKat='$kat' AND LEFT(TglTerjual,4)='2012' AND MID(TglTerjual,6,2)='02'"));
$total = mysql_query("SELECT id_kategori, nama_barang FROM barang WHERE id_kategori='$id_kat' and nama_barang like '%$_POST[barang_aset]%'and MONTH(tanggal_status) like '%$_POST[bulan]%' and status like '%$_POST[pencarian]%' ");
$counter1++;
//$persentase = ($total!=0 || $review !=0)?($review / $total) *100:0;
$total = mysql_num_rows($total);
# add chart values and category names
$FC->addChartData("$total","name=<a href='jmlaset.php?id=$id_kat'>$kat</a>");
}
# Render Chart
$FC->renderChart();
?>
</body>
</html>
How do I add an export function in this fusionchart?
Your php wrapper class for FusionCharts is not validating with the latest wrapper class please see the link
you can also export chart through FusionCharts export server by setting the attribute exportEnabled to 1. This will use their export server and will download the image at your end.
If you want to create your own export server, you can use the FusionCharts' distributable export handler. You can get useful information from this link but it uses two third party api ImageMagick and InkScape to convert SVG to required image formats. You need to install this dependencies at your end.
Having the next PHP code that produce HTML code:
(simplified function, the real one on same idea but longer with loops and so on):
<?php
function show_doc_html() {
$text_to_title = "some text from db";
?>
<html>
<head>
<title>
<?php echo $text_to_title ?>
</title>
</head>
<body>
</body>
</html>
<?
}
I would like to return a PDF to the user, without changing too much of this code. we are working under drupal so we have function that can get html string and convert it to pdf, but the former function doesn't return anything but printing to stdout. Id it possible? or should i rebuild the old function to return string?
Is that what you need?
I have used it in my project. You can just write your markup and inline css in node template using view_mode = 'PDF'
The easiest way was to encapsulate my function with "ob_start()" get all text using "ob_get_contents()", then convert it to pdf.
Something like:
function show_doc_pdf() {
ob_start();
function show_doc_html() ;
$html_var = ob_get_contents();
ob_end_clean();
//use wkhtmltopdf api on $html_var to return pdf
}
I am new to php. I need to import excel details into MySQL database in php. I downloaded 2 files reader.php & oleread.php and save that under wamp/www/folder. When I execute the following code, the server throw a error like
The filename samp.xls is not readable
Give the solution to recover this problem. my code is:
<html>
<head>
<title>Save Excel file details to the database</title>
</head>
<body>
<?php
include 'db_connection.php';
include 'reader.php';
$excel = new Spreadsheet_Excel_Reader();
?>
<table border="1">
<?php
$excel->read('samp.xls');
$x=2;
while($x<=$excel->sheets[0]['numRows']) {
$id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
$name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
// Save details
$sql_insert="INSERT INTO students (sid,name) VALUES ('$id','$name')";
$result_insert = mysql_query($sql_insert) or die(mysql_error());
$x++;
}
?>
</table>
</body>
</html>
The filename samp.xls is not readable
First thing to come to mind is that your php server cannot read your excel file ..
WAMP is on Windows, so Right-Click your excel file, and add read property to Everyone
why not import it directly into phpmyadmin?? click here
I have this PHP script that returns pictures from the database. I am using a loop now to return 5 pictures at once, but I think they are all overlapping so I am only seeing one. How can I shift each picture a couple of pixels over so I can see the other pictures?
<?php
$mysqli=mysqli_connect('localhost','root','','draftdb');
if (!$mysqli)
die("Can't connect to MySQL: ".mysqli_connect_error());
$param = isset($_GET['rarity']) ? $_GET['loopcount'] :null;
$stmt = $mysqli->prepare("SELECT display.PICTURE_ID
FROM cards
INNER JOIN display ON cards.DISPLAY_ID = display.DISPLAY_ID
WHERE display.DISPLAY_ID=? AND cards.CARD_TYPE =?" );
$cardtype='Rare';
for ($i=0; $i<=5; $i++)
{
$num[$i] = rand(16,30);
for ($j=0; $j<$i; $j++)
{
while ($num[$j] == $num[$i])
{
$num[$i] = rand(16,30);
}
$displayid= array_shift($num);
}
$stmt->bind_param("si", $displayid, $cardtype);
$stmt->execute();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: image/jpeg");
echo $image;
}
?>
You can't "display" an image with php. You do that with HTML using the <img> tag. What you do is printing the raw image data and then telling the browser It's a picture. I'm not sure what's gonna happen if you do this and print multiple images, but It's up to the browser how It should handle this probably.
This is sometimes done with one image if you for example store them as blobs in a database. But not for this purpose of displaying them.
If you want to merge images you can do this with the GD library in PHP.
You can only send one picture to the browser with Content-Type: image/jpeg. I can think of two ways to send multiple pictures.
1.Use GD to make a new picture containing all of the other pictures and send it.
2.Send an HTML page instead of the picture:
<?php
//some code which gets the images and puts them in an array - $images
?>
<!DOCTYPE HTML>
<html>
<body>
<?php foreach($images as $image):?>
<img src="data:image/jpeg;base64,<?php echo base64_encode($image);?>"/><br/>
<?php endforeach;?>
</body>
</html>
edit: It seems browsers have difficulty parsing very large HTML documents fast, so if you have large or lots of images it might be better to load them in separate HTTP requests (src="image.php?image=xxxx").