使用php下载图像链接
发布时间:2020-12-13 21:44:32 所属栏目:PHP教程 来源:网络整理
导读:我下载了此代码以用作下载按钮. ? $filename = $_GET["filename"]; $buffer = file_get_contents($filename); /* Force download dialog... */ header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); hea
我下载了此代码以用作下载按钮.
<? $filename = $_GET["filename"]; $buffer = file_get_contents($filename); /* Force download dialog... */ header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); /* Don't allow caching... */ header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); /* Set data type,size and filename */ header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($buffer)); header("Content-Disposition: attachment; filename=$filename"); /* Send our file... */ echo $buffer; ?> 问题是,文件的名称以文件名中的整个路径结束,例如,此代码: <a href="download.php?filename=images/something.jpg"> 最终得到一个名为“images_something.jpg”的图片 我想从最终文件名中删除“images_”,到目前为止我还没有运气. 谢谢您的帮助! 解决方法
如果您需要没有文件夹名称的文件名部分,则必须使用basename($filename)
http://php.net/manual/en/function.basename.php (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |