夥計。 我正在使用laravel框架的本地服務器並嘗試下載文件。 我嘗試了很多情況,但沒有爲我工作。如何解決在PHP下載的問題?
事情是我沒有得到任何錯誤。
下載wont`t開始,但在響應我有這樣的事情:
�
���JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 95��C
���}!1AQa"q2���#B��R��$3br�
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������
���w!1AQaq"2�B���� #3R�br�
$4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?���!�A���I��+�P�sB���i��?�Y�L��iG���B���Ap�����J;���;}ic=F{R�Z��
�$��z�q��~�p8�h�[email protected]��;����t�@�Fx��Ǯq�S#<������qS-
這是我用: 試過這樣:
$file = 'D:\Server\OpenServer\domains\memo.ru\public\img\avatars\\'.$file_name;
$filePath=$file;
這:
$file = "http://example.com/img/avatars/1457091259.png";
1.
set_time_limit(0);
$file = @fopen($filePath, 'rb');
while (!feof($file)) {
print(@fread($file,1024*8));
//ob_flush();
flush();
}
$handle = fopen($filePath, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, 4096);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
//header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
$real_path = 'D:\Server\OpenServer\domains\example.com\public\img\avatars\\';
$file = "http://example.com/img/avatars/1457091259.png";
$url = 'http://example.com/img/avatars/'.$tmpFileName;
$path = $real_path.$tmpFileName;
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
我有「使用響應」。瀏覽器不會開始下載。也許有其他設置? –
您在瀏覽器中訪問哪個URL並顯示什麼錯誤? – Joseph
沒有錯誤。就這個(i.yapx.ru/yO0.png)作爲迴應。 –