Jump to content

problem about xls download on Linux


srinivas6203

Recommended Posts

I want to export database values into spred sheets . But there is aproblem.

 

By using .xls extension:

 

In Linux , after save that file on desktop, if we double click on that file to open it shoot an error as following.

 

(Cannot open 2008-06-20-10-44-17.xls

The filename "2008-06-20-10-44-17.xls" indicates that this file is of type "Excel spreadsheet". The contents of the file indicate that the file is of type "plain text document". If you open this file, the file might present a security risk to your system.

 

Do not open the file unless you created the file yourself, or received the file from a trusted source. To open the file, rename the file to the correct extension for "plain text document", then open the file normally. Alternatively, use the Open With menu to choose a specific application for the file. )

 

If file open, without save onto the desktop its working fine. On Windows its working fine.

 

By using .csv extension:

 

By using .csv extension, all are fine i.e, open and downloading. But the output was not taking table formate. If we write the

following code  for table design,

<table border="1">

the above as it is code was displayed in output. But we want to display output of the above code into our desired output.

 

I think the problem was coming with the extension. If it is .xls , not downloading into Linux. If it is .csv tables are not created.

 

The following is the sample code:

 

<?php

session_start();

include "../../includes/user_functions.php";

if($_SESSION['adminlogin_user'])

{

<?php

session_start();

include "../../includes/user_functions.php";

if($_SESSION['adminlogin_user'])

{

$csv_dt=date("Y-m-d-H-i-s");

$file_name = $csv_dt;

if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE')) {

header("Content-type: application/xls");

header('Content-Disposition: attachment; filename='.date('Y-m-d-H-i-s').'.xls');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Pragma: public');

}

else {

header("Content-type: application/xls");

header('Content-Disposition: attachment; filename="'.$file_name.'.xls"');

}

echo '<table border="1" width="100%" cellpadding="5" cellspacing="1"><tr bgcolor="black"><th align="left"><font color="white">Id</font></th><th align="left"><font color="white">From</font></th><th align="left"><font color="white">To</font></th></tr>';

$result = mysql_query("SELECT * FROM astcdr order by id DESC");

while($rs = mysql_fetch_array($result))

{

echo '<tr><td align="left">'.$rs['id'].'</td><td align="left">'.$rs['accountcode'].'</td><td align="left">'.$rs['callednum'].'</td></tr>';

}

echo '</table>';

}

else {

header('location:../../index.php');

}

?>

 

 

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.