sleep until mysql load the picture - php

I've this code:
<?php
include 'connectDb.php';
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 2997 05:00:00 GMT");
header("Content-Type: text/html; charset=utf-8");
echo file_get_contents('li.gif');
sleep(3);
$id = $_GET['id'];
$row = $conn->query('SELECT picture,img FROM contacts WHERE id=\''.$id.'\' LIMIT 1');
$result = $row->fetch_assoc();
if(!empty($result['picture'])){
header("Content-type: image/".$result['img']);
echo($result['picture']);
}
What I'm trying to do: show li.gif till mysql has loaded the echo($result['picture']).
Is there a way to do this without javascript?

Related

header("Content-Disposition: attachment) not working

I have tried to export the mysql data result to excel. After click the Export button, the form will send parameter's value into doexport.php.
The result was appeared in console.
<?php
session_start(); //Start the session
include('install_lang_japanese.php');
//connect to database
$dbc=mysqli_connect(_SRV,_ACCID,_PWD,"QPL");
if(!$dbc){
die('Connect Error: ' . mysqli_connect_error());
}
if(isset($_POST['action'])){
switch($_POST['action']){
case 'senddatacar':
$start = mysqli_real_escape_string($dbc,$_POST['startdate']);
$end = mysqli_real_escape_string($dbc,$_POST['enddate']);
$sqlex = "SELECT * FROM table";
$result =mysqli_query($dbc,$sqlex) or die(_ERROR30.":".mysqli_error($dbc));
$filename="cardata".date('ymd').".xls";
header("Content-type: application/vnd.ms-excel; name='excel'");
header(sprintf("Content-Disposition: attachment; filename=$filename"));
header("Pragma: no-cache");
header("Expires: 0");
//Then echo table
break;
}
mysqli_close($dbc);
}
My problem is : i don't see any file has downloaded as excel
Response Header at console :
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Disposition:attachment; filename=cardata170929.xls
Content-Length:2988
Content-Type:application/vnd.ms-excel; name='excel'
Date:Fri, 29 Sep 2017 05:02:19 GMT
Expires:0
Pragma:no-cache
Server:Apache/2.2.22 (Ubuntu)

export and download as csv in php not working in chrome and IE but working in firefox

I have a simple web page which pulls some data from DB and displays it in a html table and stores the data in some session variables.
I have a button "Export to csv" which calls a page which exports the results to a csv file.
The code for ExportToCsv file is:
<?php
session_start();
include "conn/sqlserverConn.php";
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
$data = $_SESSION['data'];
$rows = $_SESSION['row'];
$header = $_SESSION['header'];
download_send_headers("data_export_" . date("Y-m-d") . ".csv");
$file = fopen("php://output", 'w');
fputcsv($file,$header);
for($i=0; $i<$rows; ++$i)
{
$valuesArray=array();
foreach($data[$i] as $name => $value)
{
$valuesArray[]=$value;
}
fputcsv($file,$valuesArray);
}
fclose($file);
die();
?>
My code is working flawlessly in firefox but it is not working in chrome or IE. On chrome and IE it is showing error 404 (Object not found!). Please tell me what is the problem ?
As outlined in the blog article at: http://www.exchangecore.com/blog/php-output-array-csv-headers/, I tested the following and it worked in IE8-11, and in chrome version 34. I presume it will work in other browsers fine as well.
Headers to use:
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=' . $fileName);

Export large data to CSV using PHP

I am trying to export some data to CSV using PHP.
My code:
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
$givenTerm = $_POST['TextBoxList'];
$sql_query = "select * from some_table where key=".$givenTerm;
$result = sqlsrv_query($conn,$sql_query);
$r1 = array();
$file = fopen("php://output", 'w');
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)){
$valuesArray=array();
foreach($row as $name => $value)
{
$valuesArray[]=$value;
}
fputcsv($file,$valuesArray);
}
fclose($file);
download_send_headers("data_export_" . date("Y-m-d") . ".csv");
die();
Here I am receiving a search-value from a form in another page and then triggering a query based on it. The code is working fine for smaller data-sets(up to 100). But when the number of rows is more in the result (around 600-700) then the code crashes. Please tell me how to fix this.
P.S. I am using Sql Server 2012 for the database.
Instead of first getting all results in a single array and then outputting it, you could also fetch it row by row and outputting each row directly.
That way you won't need the massive amount of memory to fit the entire array in.

Generate a Doc File with an Image

<?php
$docName = "testdoc";
header("Expires: Mon, 26 Jul 2020 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Type: application/msword; charset=ISO-8859-1");
header("Content-Disposition: attachment; filename=\"".$docName.".doc");
#/ Create and format your text using HTML, its simple stuff ... trial and error ;)
echo '<img src="logo.gif" />';
?>
Soumya Sarkar
Hi I got this following code from google to generate a Doc file by php. But I am unable to put any image there. Can anybody help me with it?
It requires the link, you will need to host the images online in order for the image to be shown on the doc.
Try this and it is working:-
echo "<img src='http://i.imgur.com/MJ5Sa.jpg' />";

How to prevent from session restore on back button in ubuntu?

Guys please tell me how to prevent from session restore on back button in ubuntu ?
session_cache_limiter( FALSE );
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0'");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
this works in xp but not in ubuntu.

Categories