php或html网页,上面有个文件链接,¥本文来%源[email protected]搞@^&代*@码)网5搞gaodaima代码点击它的时候,怎么样做是让这个文件打开,怎么样做是让它下载?就是出现那个下载对话框。
回复内容:
php或html网页,上面有个文件链接,点击它的时候,怎么样做是让这个文件打开,怎么样做是让它下载?就是出现那个下载对话框。
这样是进行文件的下载:
<code>function downloadfile($filename,$storage) { if(! is_file($storage)) exit('文件不存在!'); if(!$fp = fopen($storage, 'r')) exit('error'); header('Content-Type: application/octet-stream;charset=utf-8'); if(preg_match("/Trident/", $_SERVER["HTTP_USER_AGENT"])) { header('Content-Disposition: attachment; filename="'.utf8togbk($filename).'"'); } else { header('Content-Disposition: attachment; filename="'.$filename.'"'); } header('Content-Transfer-Encoding: binary'); while(! feof($fp)){ echo fread($fp,1025); } fclose($fp);}</code>
打开文件应该是浏览器的行为吧?
通过php的header()方法,来修改html头部内容,来达到目的