前台HTML:
添加download属性,不打开download.php页面
download.php
1:从数据库中导出内容
2:fread输出到页面
connect("127.0.0.1","root","root","amazon"); //首先从t_crawl_url表中获取对应的id值,拼接sql语句 $sql="select id from t_crawl_url where crawl_id=".$crawlId; $request=$conndb->queryarr($sql); $str=''; if($request){ foreach($request as $key => $values){ $str.="crawl_url_id='".$values['id']."' or "; } $str=substr($str,0,strlen($str)-4); //echo $str; }else{ echo "error"; exit; } $sql="select pid,price Into OutFile '".$filePath.$fileName."' fields terminated by ',' lines terminated by '\r\n' From `t_product` where ".$str; $request=$conndb->query($sql); if($request){ /*echo "";*/ }else{ echo ""; exit; } //此处给出你下载的文件名 $file = fopen($filePath.$fileName, "r"); //打开文件 //输入文件标签 header("Content-type:application/octet-stream "); header("Accept-Ranges:bytes "); header("Accept-Length: " . filesize($filePath.$fileName)); header("Content-Disposition: attachment; filename= ".$fileName); //输出文件内容 echo fread($file, filesize($filePath . $fileName)); fclose($file); ?>