Jump to Another Page After Generate Excel File in PHP - php

I'm making a form (form.php) for user to insert data, after user finish inserting data, form action will jump to formGenerateXLS.php (using POST method) for generate user data to XSL file. In the bottom of formGenerateXLS.php I put a javascript code to jump to dashboard (home.php) but it fail. The Excel file successfully generate but javascript code not working. How to work with that?
if(isset($_POST['issue_time'])){
$product_desc = $_POST['product'];
$filename_excel = date("Ymd_")."$product_desc";
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$filename_excel.xls");
echo "<table border='1'>";
echo "<tr>";
echo "<th colspan='3' bgcolor='#1bf3b3'>New Ticket Request</th>";
echo "</tr>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td></td>";
echo "<td>User</td>";
echo "</tr>";
echo "</table>"
}
echo "<script>window.location='home.php'</script>";

Because echo does not execute the command, but simply writes it to the file.
In order to reposition a php file, use the header () function, for example header ('location: home.php');.

Related

How to open a pdf located in a root folder in codeigniter without downloading the file?

I am a newbie in codeigniter. I am working on a site that can upload and view a PDF file. I've already succeeded on the upload.
The problem is, whenever I want to view the uploaded file in the browser, it is automatically downloading. I want to view the PDF file in the browser. how can i do it?
here is the code in my VIEW
<?php
echo '<table class = "table table-striped">';
echo '<tr>';
echo '<th class="table_head">Filename</th>';
echo '<th class="table_head">Department</th>';
echo '<th class="table_head">Uploaded by</th>';
echo '<th class="table_head"></th>';
echo '</tr>';
if(isset($tbl_uploaded) && is_array($tbl_uploaded) && count($tbl_uploaded) > 0)
{
foreach($tbl_uploaded as $uploaded)
{
echo '<tr>';
echo '<td>'. $uploaded->name .'</td>';
echo '<td>'. $uploaded->department .'</td>';
echo '<td>'. $uploaded->uploader .'</td>';
echo '<td>View</td>';
echo '</tr>';
}
}
echo '</table>';
?>
thanks in advance guys
You have to change your browser setting.if you are using firefox just go to open menu then
option -> application then select portable documentation format (pdf) action to set preview in firefox.
you can try this one, I am using this code to generate a letter from my database, I am also using a codeigniter.
function createPDF()
{
$data['']= $this->input->post("");
$this->load->library('mpdf');
$this->load->model('');
$query = $this->'your_model'->'model_name'($data);
if($query!=null)
{
$hello .=' Insert your letter here
<p>' .$data->something. '</p> //fetch something from your database';
$mpdf=new mPDF('ISO-8859-1','letter', 10, 'Arial', 15, 15, 16, 16, 9, 9, 'P');
$stylesheet = file_get_contents(base_url().'css/pdf.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->SetHTMLHeader('<img src="'.base_url().'css/edrsletter.jpg"></img>');
$mpdf->WriteHTML($hello);
$mpdf->SetFooter(' Sample PDF template - {PAGENO}');
$mpdf->Output();
}
}

Allow user to save html table locally to csv, PHP & javascript

EDITED:
Problem: I have a dynamically-generated html table on a page that I want the user to be able to click a button and download to their computer.
Setup: file called main.php which contains all processing, variables, arrays, etc. => feeds all data into webpages, one of which is table.php (this page dynamically echoes one of the arrays from main.php into an html table) => link in table.php to tblProcess.php with the headers that outputs the file for download.
code I have now in tblProcess.php file that works
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=$filename");
// Disable caching
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies
outputCSV(array(
array("name 1", "age 1", "city 1"),
array("name 2", "age 2", "city 2"),
array("name 3", "age 3", "city 3")
));
function outputCSV($data) {
$output = fopen("php://output", "w");
foreach ($data as $row) {
fputcsv($output, $row); // here you can change delimiter/enclosure
}
fclose($output);
}
link in table.php to tblProcess.php
<a id="dl" href="downloadProcess.php">Download</a>
with that dummy data array in the file, when you click the link all works as expected and it asks you to download filename.csv (with the dummy data in it) so I know the code is fine.
The big issues I'm having is how to get my html table from table.php into this file. Posting it via ajax and retrieving via $_POST hasn't worked at all no matter how I try, but I can't figure out how else to get this table into this file?
the way the table is echoed dynamically in table.php (from an array included from main.php)
echo "<div id='assnTable'><table id='assign' border='1px'>";
echo "<thead><th>uniqueID</th><th>Name</th><th>FundCode</th><th>Amount $</th><th>FundCode</th><th>Amount $</th><th>Totals:</th></thead>";
$count = 1;
echo "<tbody>";
foreach($assn as $unID => $asnm) {
oddClass($count);
echo "<td>{$unID}</td>";
echo "<td>";
echo $stu[$unID]['USER_LAST_NAME'].", ".$stu[$unID]['USER_FIRST_NAME'];
echo "</td>";
foreach($asnm as $fund => $amt) {
echo "<td>{$fund}</td>";
echo "<td class='sumCell'>{$amt}</td>";
}
$count++;
echo "</tr>";
}
echo "<tr class='totalRow'><td></td><td></td><td></td><td></td><td></td><td id='last'><b>Total:</b></td></tr>";
echo "</tbody></table></div>";
In closing, my big question is, HOW do I get this html table into the processing file that downloads the file? I can clean and prepare it into an array or whatever I need, I just can't figure out how to get it into the other file. Trying to link an ajax post to the clicking of the download link disables the download part of it.
Thanks!

Display image in php

how to display image in html by retrieving it from mysql database.
i have the following code but only text is being displayed in place of image.
How to display the image instead of the text of image.
Code:
while ($row = mysql_fetch_assoc($result))
{
//echo "<div>";
//echo "<div class=\"slide-image\">";
print $row['Image'];
//echo "</div>";
echo "<div class=\"slide-text\">";
echo $row['Head'];
echo $row['Description'];
//echo "</div>";
//echo "</div>";
}
It displays the resulting JPEG as text, which as you might imagine is very difficult to interpret.
You have to set the Content-Type header with PHP. If it is JPEG it will be image/jpeg. You can set it with:
header('Content-Type: image/jpeg');
Be sure to set that header before outputting any data.
update
But in your file as you are outputting image data and text data from same document you cant set its header type as multiple types.
one option would be
while ($row = mysql_fetch_assoc($result))
{
echo "<div>";
echo "<div class=\"slide-image\">";
echo "<img src='image_render.php?id=".$row['some_key_for_record']."'";
//print $row['Image']; we are moving it to an external page
echo "</div>";
echo "<div class=\"slide-text\">";
echo $row['Head'];
echo $row['Description'];
echo "</div>";
echo "</div>";
}
and in image_render.php
//code to pull data from db according to $_GET['id'];
header('Content-Type: image/jpeg');
print $row['Image'];
//no text data to be output from here
If you are stroing the image source(full path) in your MYSQL table then you can able to print the html img tag inside your php like a html div. You can do it by this way,
while ($row = mysql_fetch_assoc($result))
{
//echo "<div>";
//echo "<div class=\"slide-image\">";
echo '<img src='".$row['Image']."' width="100" height="100" />';
//echo "</div>";
echo "<div class=\"slide-text\">";
echo $row['Head'];
echo $row['Description'];
//echo "</div>";
//echo "</div>";
}
Note :
If you want only the image to be displayed in your web page then you can do it with header('Content-Type: image/jpeg');

how to add html & javascript after PHP exit

Please Help, nothing i add after the ?> works, i tried to put the code in a echo, but its not working would someone please put together a JSFiddle for me or point me in the right direction, i am fairly new with PHP, Thanks for the help
<?php
$filepath = 'http://www.godsgypsychristianchurch.net/music.json';
$content = file_get_contents($filepath);
$json = json_decode($content, true);
foreach ($json['rows'] as $row)
{
if ($_GET['album'] == $row[doc]['album'])
{
echo "<title>{$row[doc]['album']}</title>";
echo "<table align=\"center\" border=\"0\"><tr><td valign=\"top\" width=\"330\">";
echo "<img src=\"{$row['doc']['artwork']}\" alt=\"my image \" width=\"250\" /><br /><br />";
echo "<div class=\"albuminfo\" id=\"albuminfo\">";
print ' Download entire album.<p>';
echo "<font color=\"#fff\">Album: {$row[doc]['album']}</font><br />";
echo "<font color=\"#fff\">Church: {$row[doc]['church']}</font><br />";
echo "<font color=\"#fff\">Description: {$row[doc]['des']}</font><P><br /><P>";
echo "Tweet<br><br>";
print '<div id="like-button"></div>';
echo "<td valign=\"top\">";
echo "<div class=\"playlist\" id=\"playlist\">";
echo "<ol>";
$songCount = 0;
foreach ($row['doc']['tracks'] as $song) {
++$songCount;
$songUrl = $row['doc']['baseurl'] . urldecode($song['url']);
echo "<li>{$song['name']}<div id=\"download\">Download</li>";
}
echo "</ol>";
echo "<br><div id=\"player\"><audio preload></audio></div>";
echo "</div>";
echo "<P>";
echo "<small>To download a single MP3 at a time:</br><b>Windows OS:</b> hold the ALT button on the keyboard and click the Download button<br><b>Mac OSX:</b> hold the OPTION button on the keyboard and click the Download button<P><BR><b>Controls:</b><br>Play/Pause = spacebar</br>Next track = Right arrow<br>Previous track = Left arrow";
echo '</tr></td></table>';
}
}
exit;
?>
<!----NOTTING SHOWING UP---->
<!-- begin htmlcommentbox.com -->
<div id="HCB_comment_box">HTML Comment Box is loading comments...</div>
<script type="text/javascript" language="javascript" id="hcb"> /*<!--*/ if(!window.hcb_user){hcb_user={};} (function(){s=document.createElement("script");s.setAttribute("type","text/javascript");s.setAttribute("src", "http://www.htmlcommentbox.com/jread?page="+escape((window.hcb_user && hcb_user.PAGE)||(""+window.location)).replace("+","%2B")+"&opts=0&num=10");if (typeof s!="undefined") document.getElementsByTagName("head")[0].appendChild(s);})(); /*-->*/ </script>
<!-- end htmlcommentbox.com -->
Because you are using exit, which terminates the script. Get rid of that and it will continue to output the HTML underneath.
http://php.net/manual/en/function.exit.php
Omit the exit.
Exit will end Php processing.
With php exit the parser stops, and hands back all the content gathered until that point to the web server. Simply delete the exit; row.

Add an Outlook calendar event from a link on a web page

Anyone knows how i can add a anchor to a web page that will force an Outlook Calendar file download? I need the file to open with outlook and the calendar info to be added to the user's calendar.
How can I create the MS outlook calendar files? Is there a standard/documented way I can create these calendar files using a script/automated way? (the script will be written in php)
thanks -
<?php
//This is the most important coding.
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=filename.ics");
echo "BEGIN:VCALENDAR\n";
echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
echo "VERSION:2.0\n";
echo "METHOD:PUBLISH\n";
echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
echo "BEGIN:VEVENT\n";
echo "CLASS:PUBLIC\n";
echo "CREATED:20091109T101015Z\n";
echo "DESCRIPTION:How 2 Guru Event\\n\\n\\nEvent Page\\n\\nhttp://www.myhow2guru.com\n";
echo "DTEND:20091208T040000Z\n";
echo "DTSTAMP:20091109T093305Z\n";
echo "DTSTART:20091208T003000Z\n";
echo "LAST-MODIFIED:20091109T101015Z\n";
echo "LOCATION:Anywhere have internet\n";
echo "PRIORITY:5\n";
echo "SEQUENCE:0\n";
echo "SUMMARY;LANGUAGE=en-us:How2Guru Event\n";
echo "TRANSP:OPAQUE\n";
echo "UID:040000008200E00074C5B7101A82E008000000008062306C6261CA01000000000000000\n";
echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
echo "X-MS-OLK-CONFTYPE:0\n";
//Here is to set the reminder for the event.
echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT1440M\n";
echo "ACTION:DISPLAY\n";
echo "DESCRIPTION:Reminder\n";
echo "END:VALARM\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
?>
Just in case someone needs it in PHP. I was searching found this.
Create an outlook .ics file
See here for more information. The example is in .NET, but it is simply writing output, so very easy to translate to PHP.

Categories