这篇文章介绍的内容是关于php文件下载 重命名,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
$file_url = “./本地路径” $out_filename = ‘下载后自动保存的名字’; if(!file_exists($file_url)) { echo "不存在"; }else{ header('Accept-Ranges: bytes'); header('Accept-Length: ' . filesize( $file_url )); header('Content-Transfer-Encoding: binary'); header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $out_filename); header('Content-Type: application/octet-stream; name=' . $out_filename); if(is_file($file_url) && is_readable($file_url)){ $file = fopen($file_url, "r"); echo fread($file, filesize($file_url)); fclose($file); } }
$file_ur = ‘远程文件地址’; $out_filename='下载后自动保存的文件名'; $file = @fopen($file_url, "r"); if($file){ $content=""; while(!feof($file)){//测试文件指针是否到了文件结束的位置 $data=fread($file,1024); $content.=$data; } fclose($file); $filesize = strlen($content); header('Accept-Ranges: bytes'); header('Accept-Length: ' . $filesize); header('Content-Transfer-Encoding: binary'); header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $out_filename); header('Content-Type: application/octet-stream; name=' . $out_filename); echo $content; }else{ echo "文件不存在"; }
相关推荐:
以上是php文件下载 重命名的详细内容。更多信息请关注PHP中文网其他相关文章!