【发布时间】:2022-01-01 11:51:31
【问题描述】:
我创建了一小段代码来测试 readfile() 的功能,我想用它来开发我的大型项目。作为测试,这是我写的代码:
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post">
<input type="submit" value="submit" name="Submit1"><br/><br/>
<?php
if(isset($_POST["Submit1"]))
{
$filetry = 'Cat.jpg';
if (file_exists($filetry)){
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filetry).'"');
header('Expires: 0');
header('Cache-Control: must revalidate');
header('Pragma: public');
header('Content-Length'.filesize($filetry));
readfile($filetry);
exit;
}
}
?>
</form>
</body>
</html>
我使用https://www.php.net/manual/en/function.readfile.php的PHP手册帮助我构建代码,但我仍然不知道为什么它无法成功下载图像 and gives me a "Could not load image error". 。我读过较大的图片可能无法下载,但这张图片只有 900KB 左右。有什么我做错了吗?我将不胜感激。
【问题讨论】: