您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 甘孜分类信息网,免费分类信息发布

php处理文件下载的代码

2024/2/22 4:02:30发布22次查看
用在服务器上提供下载的php代码,可以指定被下载的文件名,可以动态指定文件内容
// local file that should be send to the client$local_file = 'test.zip';// filename that the user gets as default$download_file = 'your-download-name.zip'; if(file_exists($local_file) && is_file($local_file)) { // send headers header('cache-control: private'); header('content-type: application/octet-stream'); header('content-length: '.filesize($local_file)); header('content-disposition: filename='.$download_file); // flush content flush(); /* ** you can also remove the following part and ** replace it trough a database command fetching ** the download data */ // open file stream $file = fopen($local_file, rb); // send the file to the browser print fread ($file, filesize($local_file)); // close file stream fclose($file);}else { die('error: the file '.$local_file.' does not exist!');}
复制代码
php
甘孜分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录