1
私はイメージホスティング用のサイトを運営しています。好きなだけユーザーのためにイメージをダウンロードする機能があります。しかし、ダウンロードは全く機能しません。それは私にそれが無効な画像です。しかし、私は、私は私のサイトで持っているものと同じであるダウンロードサイズは、ここに私のコードは、すべてのボディのヘルプ外部リンクからファイルをダウンロードするには
<?php
function get_remote_size($url) {
$headers = get_headers($url, 1);
if (isset($headers['Content-Length'])) return $headers['Content-Length'];
if (isset($headers['Content-length'])) return $headers['Content-length'];
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'),
));
curl_exec($c);
return curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);
}
$url = 'http://localhost/ds.jpg';
$name = 'Beezfeed.jpg';
// Fetch and serve
function do_the_download($url,$name) {
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime($url)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: image/jpg');
header('Content-Disposition: attachment; filename="'.$name.'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '. get_remote_size($url));
header('Connection: close');
readfileChunked($url);
}
if(isset($_POST["downloadfile"])) {
do_the_download($url,$name);
}
function readfileChunked($filename, $retbytes=true){
$chunksize = 1*(1024*1024);
$buffer = '';
$cnt = 0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
?>
<form method="POST">
<input type="submit" value="DOWNLOAD FILE" name="downloadfile"/>
</form>
私はちょうどCSSとサイトを美しくするために他のものなしに、生のコードを与えている可能です。おかげで、事前に試して
ありがとうございます – Kumar