php用header()实现文件下载功能代码:
<p>function download($file_url,$new_name=''){</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/950">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680003823895.png" alt="ViiTor实时翻译">
</a>
<div class="aritcle_card_info">
<a href="/ai/950">ViiTor实时翻译</a>
<p>AI实时多语言翻译专家!强大的语音识别、AR翻译功能。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="ViiTor实时翻译">
<span>116</span>
</div>
</div>
<a href="/ai/950" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="ViiTor实时翻译">
</a>
</div>
if(!isset($file_url)||trim($file_url)==''){<br /> return '500';<br /> }<br /> if(!file_exists($file_url)){//检查文件是否存在<br /> return '404';<br /> }<br /> $file_name=basename($file_url);<br /> $file_type=explode('.',$file_url);<br /> $file_type=$file_type[count($file_type)-1];<br /> $file_name=trim($new_name=='')?$file_name:urlencode($new_name).'.'.$file_type;<br /> //输入文件标签phpernote<br /> header("Content-type: application/octet-stream");<br /> header("Accept-Ranges: bytes");<br /> header("Accept-Length: ".filesize($file_url));<br /> header("Content-Disposition: attachment; filename=".$file_name);<br /> //输出文件内容<br /> @readfile($file_type);<br />}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号