php图像下载和日期校正


php image download and date correction

我为我的图像托管网站制作了一个简单的图像下载程序。不过我面临一个问题。当我下载图像时,它坏了,我无法获得正确的代码。有人请看一看。

所以我的图片按日期存储在我的image.uploads文件夹中。所以我需要在下载之前得到图片的日期。这是我到目前为止得到的。

<?php   
if(isset($_POST['file_name'])){
$file = $_POST['file_name'];
header('Content-type: image/jpg');
header('Content-type: image/png');
header('Content-type: image/gif');
    header('Content-Disposition: attachment; filename="'.$file.'"');
    readfile('image.uploads/' . date("jS F Y", $image_details->image_date) . '/'.$file);
exit();
}
?>

idk如果我把图像日期部分弄对了,我该如何让它显示为这样:"25-07-13":/html部分:$image_main是图像名称。

<form action="view-image.php" method="post" name="downloadform">
  <input name="file_name" value="<?=$image_main?>" type="hidden">
  <input type="submit" value="Download the image">
</form>

非常感谢任何愿意提供帮助的人!

可能您设置了错误的内容类型,我在下载文件时设置了这些标题:

header("Content-Type: ".$mime);
header("Cache-   Control: no-store, no-cache");
header("Content-Description: ".$mustang);
header("Content-Disposition: attachment;filename=".$mustang);
header("Content-Transfer-Encoding: binary");

其中$mime是mime类型,$mustang是文件名,基本上你试图做的是不正确的,因为设置的contet类型总是image/gif
要查找文件的mime类型,请使用php函数finfo_open