所以我做了一個圖像託管網站和即時通訊嘗試添加一個選項來下載圖像。我有一個腳本,它的工作原理是,所有的圖像都按日期存儲在文件夾中。所以在腳本上它只是一個靜態url。如何使這變成像一個功能,將其添加到實際的圖像頁面,如「www.mysite.com/view-image/123456.png?download」圖像下載功能
繼承人的代碼:
<?php
if (!$filename) {
// if variable $filename is NULL or false display the message
echo $err;
} else {
// define the path to your download folder plus assign the file name
$path = 'image.uploads/' .$imagedate/'.$filename;
// check that file exists and is readable
if (file_exists($path) && is_readable($path)) {
// get the file size and send the http headers
$size = filesize($path);
header('Content-Type: application/octet-stream');
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
// display the error messages if the file can´t be opened
$file = @ fopen($path, 'rb');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file);
exit;
} else {
echo $err;
}
} else {
echo $err;
}
}
?>
所以你在$路徑上工作?爲什麼不在這裏查詢並獲得img匹配呢?我不知道一些ID? –
你是什麼意思?即時通訊新的PHP。你能幫我重寫一下嗎?我需要它能夠在圖像下方編碼。對於IDS,只是讓他們和生病改變他們 – VladL
你說這是工作?即時通訊與你說的話混淆,這是行不通的?你正在建造它 –