【问题标题】:How to add image name with extension to hyperlink trailing end php如何将带有扩展名的图像名称添加到超链接尾端php
【发布时间】:2017-09-25 04:28:08
【问题描述】:

我想弄清楚如何使 myimage.jpg 成为超链接的尾端的一部分?

到目前为止,我已经下载了图片,但不确定如何使超链接看起来像:

http://192.168.0.11/myimage.jpg

到目前为止我的代码:

<?php

$file = "./my_image.jpg";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>

【问题讨论】:

    标签: php download endpoint


    【解决方案1】:

    您可以使用echo 在链接末尾打印您的$file 变量。

    这样,

    <a href="//192.168.0.11/<?php echo $file; ?>">
    

    这将创建在HTML 中查看的链接,

    <a href="//192.168.0.11/myimage.jpg">
    

    【讨论】:

    • 谢谢。我不想传递给 HTML。我想在 Android 中使用 Glide 来使用图像。目前它确实获取图像并显示它。
    • 是的,一旦我在下载而不是显示标题时删除了标题。
    • 当我查看 HTML 页面时,只是想看看它从 PHP 中得到了什么样的输出。我得到了: 我通过以下方式调用了文件:
    猜你喜欢
    • 1970-01-01
    • 2014-09-06
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    相关资源
    最近更新 更多