Mam mały problem bo robię skrypt downloadu i nie wiem jak za pomocą php pobrać plik.
np klikamy w link który wygląda tak:
http://localhost/index.php?id=pobierz&fileid=1
i zmienna fileid jest wpisana jako weryfikacja wiersza w sql.
później z tego wiersza jest wypisana jego ścieżka (download/test1.rar), następnie ten kod znalazłem na:
http://us3.php.net/manual/en/function.readfile.php
i powinno pobierać plik.
<?
$read_ = mysql_query("SELECT * FROM download_file WHERE id='".$fileid."'") or die("Błąd! Nie można wykonać.");
while($r = mysql_fetch_array($read_)) {
$id=$r['id'];
$file=$r['file_dir'];
if (file_exists($file)) {
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, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
?>
A zamiast tego wyskakuje masakryczna ilość błędów:
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 8
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 9
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 10
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 11
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 12
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 13
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 14
Warning: Cannot modify header information - headers already sent by (output started at D:\WebServ\httpd\theme\index.php:18) in D:\WebServ\httpd\theme\index.php(40) : eval()'d code on line 15
Rar!��s�� �������