0

is it possible in php to download uploaded excel sheet by taking only its filename from the database?? if so solve my pblm..thank u..:)

4
Contributors
7
Replies
36
Views
3 Years
Discussion Span
Last Post by paulkd
0

i have downloaded the uploaded excel sheet.but am geting this error...my code is..
download.php

<?php 
include("dbcon.php");
$uid=$_GET['dn'];
$re=mysql_query("select uploadfile from countamount where lid='$uid'");
$ff=mysql_fetch_array($re); 
$filename=$ff[0];
header("Content-Length: " .filesize($filename)); 
header('Content-Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename='.$filename); 
ob_clean();
flush();
readfile($filename); 

?>


help me :'( advnc thnk u..
Attachments Capture.JPG 29.74 KB
1

Try another file, maybe that one was corrupt on upload or something.

0

now again..:( i can download the excel..bt while hosting it showing error..error means am not able to download.. this is my download code...

<?php 
include("dbcon.php");
$uid=$_GET['dn'];
$re=mysql_query("select filename from file where lid='$uid'");
$ff=mysql_fetch_array($re);
$dir = "upload/";
$filename= $dir.$ff[0];
header('Content-disposition: attachment; filename="'.$filename.'"');
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Type: application/vnd.ms-excel");
header('Content-Length: ' . filesize($filename));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush(); 
readfile($filename);
 ?>
0

Using your original code and looking at header in the php.net documentation I've constructed this:-

if(file_exists($filename)) {
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.$filename.'"');
    readfile($filename);
} else {
    die('not ok');
}

Edited by paulkd: removed some info

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.