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..:)

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..

what error u getting

error is attached in the last thread itslf..

Now i can open the excel sheet..but it is empty!

Member Avatar for iLikePHP

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

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);
 ?>

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');
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.