Jump to content

file download problem in server?


phpmady

Recommended Posts

hi,

 

 

I want to download the file, where i have the search query in session variable, in my local system its working good, but in server its not working, any guidance please

 

<?php
include("global.php");
// Original PHP code by Chirp Internet: www.chirp.com.au 
// Please acknowledge use of this code by including this header. 

function cleanData(&$str) 
{
$str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); 
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
} 

$sql = $_SESSION['emp_search_sql'];
// file name for download 
$filename = "employees_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); 
header("Pragma: no-cache");


$flag = false;
$result = $DB_site->query($sql) or die('Query failed!');
while(false !== ($row = mysql_fetch_assoc($result)))
{
if(!$flag) 
{
// display field/column names as first row 

echo implode("\t", array_keys($row)) . "\n"; $flag = true; 
} 
array_walk($row, 'cleanData'); 
echo implode("\t", array_values($row)) . "\n";
}

?>

 

 

Thanks

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.