虽然下载图像.文字出版社



我正在.jpg通过 .PHP 文件。它工作完美。我正在使用空白.HTML页面上的链接进行测试。

但是现在我想在 Wordpress 页面上集成链接,单击后似乎无法连接到.php文件。

有人知道如何将 href URL 连接到.php文件吗?

.HTML

<a href="download-image.php">Download</a>

.PHP

<?php
$file = 'images/test.jpg';
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$ext = pathinfo($file, PATHINFO_EXTENSION);
$basename = pathinfo($file, PATHINFO_BASENAME);
header("Content-type: application/".$ext);
// tell file size
header('Content-length: '.filesize($file));
// set file name
header("Content-Disposition: attachment; filename="$basename"");
readfile($file);
exit;
?>

谢谢!

你需要使用正确的路径。

我假设您的文件位于根文件夹中。因此,请尝试添加"/":

<a href="/download-image.php">Download</a>

从主题文件夹:

<a href="/wp-content/themes/MYTHEME/download-image.php">Download</a>

最新更新