Witam,
Mam następujący problem: mam index.php, w którym przetwarzam strony poprzez id... i mam download, gdzie pokazuje jakie są pliki w mysql i po wciśnięciu je ściąga... o to błąd po wciśnięciu w link:
Kod
Warning: Cannot modify header information - headers already sent by (output started at /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/index.php:13) in /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/page/get_file.php on line 30
Warning: Cannot modify header information - headers already sent by (output started at /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/index.php:13) in /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/page/get_file.php on line 31
Warning: Cannot modify header information - headers already sent by (output started at /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/index.php:13) in /home/vhost/home/pilach-admin/pilachowski.pl/home/kuba/public_html/page/get_file.php on line 32
%PDF-1.4 %ĐÔĹŘ 4 0 obj << /Length 888 /Filter /FlateDecode >> stream xÚVKoă6žűWčHCR|´b´wѢ şőKÍ*śe×r`Čżž3$ĺ*śháĢ8Żofžäţqńć'pX.ĄŇĹăď
ř#¸ŁˇşřĚ>-dá),KĺŰËR)čňÔžě_ß-~|\@!đ
Ö;YV8îź/6űĹÁÁŤ˘Ęô
ŁežxłÚCńpX|ŔĎ_ÂRYýs¤řů(jžCĘťâU÷
Vťâ#:¸°Ę Ž{Ę]Âso¤ÉŠ/šŠ|JŕĄŮ
Ň;Ę_ą§ÓË1¤ăęˇ|W_Űf-+EoÁŘ]:ÖţźÚťlrű.đWŚ
Tych dziwnych znaków jest duuużo więcej, więc ich nie wstawiłem...
O to kody:
download.php
<?php
// Connect to the database
include 'connection.php';
// Query for a list of all existing files
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
// Check if it was successfull
if($result) {
// Make sure there are some files in there
echo '<p>There are no files in the database</p>'; }
else {
// Print the top of a table
echo '<table width="100%"> <tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b> </b></td>
</tr>';
// Print each file
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a href='index.php?go=get_file&id={$row['id']}'>Download</a></td>
</tr>";
}
// Close table
}
}
else
{
echo 'Error! SQL query failed:'; echo "<pre>{mysql_error}</pre>"; }
?>
get_file.php (w tym jest błąd :/)
<?php
// Make sure an ID was passed
// Get the ID
// Make sure the ID is in fact a valid ID
if($id <= 0) {
die('The ID is invalid!'); }
else {
// Connect to the database
include 'connection.php';
// Fetch the file information
$query = "
SELECT `mime`, `name`, `size`, `data`
FROM `file`
WHERE `id` = {$id}";
if($result) {
// Make sure the result is valid
// Get the row
// Print headers
header("Content-Type: ". $row['mime']); header("Content-Length: ". $row['size']); header("Content-Disposition: attachment; filename=". $row['name']);
// Print data
}
else {
echo 'Error! No image exists with that ID.'; }
}
else {
echo "Error! Query failed: <pre>{mysql_error}</pre>"; }
}
}
else {
echo 'Error! No ID was passed.'; }
?>
index.php
<?php
// zmienna potrzebna do prawidlowego wczytania includowanych plikow
$add_site = true;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="Reply-to" content="kess@snug.pl" />
<meta name="Author" content="Krzysztof Szypulski" />
<head>
<title>Strona Kuby P.</title>
<style type="text/css">
<!--
body {
font-family: Verdana, Arial;
font-size: 12px;
}
-->
</style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%" colspan="3"><?php include "include/naglowek.php"; ?></td>
</tr>
<tr>
<td width="15%" valign="top"><?php include "include/menu_lewe.php"; ?></td>
<td width="70%" valign="top">
<?php
// zmienna $go przekazana metoda GET
$go = $_GET['go'];
// sprawdzamy czy zmienna $go nie jest pusta
// sprawdzamy czy plik o danej nazwie istnieje
if(is_file("page/$go.php")) include "page/$go.php"; // jezeli plik nie istnieje wyswietla się komunikat
else echo "<br />Nie ma takiej strony :-("; }
// jezeli zmienna $go jest pusta wyswietla się strona glowna
else include "page/start.html";
?>
</td>
<td width="15%" valign="top"><?php include "include/menu_prawe.php"; ?></td>
</tr>
<tr>
<td width="100%" colspan="3"><?php include "include/stopka.php"; ?></td>
</tr>
</table>
</body>
</html>
Baaardzo proszę o pomoc i dzięki z góry!
Ten post edytował kuba_pilach 20.02.2011, 12:26:03