Reputation: 15646
I am creating Excel sheet in PHP5 my script is:
<?
$csv_hdr="ID,Image\n"; // Column Heading
$rows=array();
$rows[0]=['img/logo_0.png'];
$rows[1]=['img/logo_1.png'];
$rows[2]=['img/logo_2.png'];
$rows[3]=['img/logo_3.png'];
$rows[4]=['img/logo_4.png'];
for($r=0;$r<sizeof($row);$r++){
?>
<tr>
<td align="left" valign="center">
<? $csv_output .= "<img src='".$r."'/>" . ", ";?>
</td>
<td align="left" valign="center">
<? $csv_output .= $row[$r] . "\n";?>
</td>
</tr>
<? }
$filename = rand(0,999999);
$csv_output = $csv_hdr.$csv_output;
$fp = fopen('report_csv/'.$filename, "w");
fwrite($fp, $csv_output);
fclose($fp);
$fileType = 'application/csv';
$fileData ="<?php
header('Content-disposition: attachment; filename=".$filename."');
header('Content-type: ".$fileType."');
readfile('".$filename."');
?>";
$phpFile = 'report_csv/report_'.$csv.'.php';
$fh = fopen($phpFile, 'w') or die("can't open file");
fwrite($fh, $fileData);
fclose($fh);
?>
It works fine but it shows image path not the exact image although I have tested all script and folders are there..
Upvotes: 0
Views: 866
Reputation:
I don't think we can embedd an image into a CSV file with the way you are trying.
If you are trying to create an Excel file with images then you can try out a library called PHPExcel.
Upvotes: 2