Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]download w szablonie
Forum PHP.pl > Forum > Przedszkole
kuba_pilach
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čH—CR|´‡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
  1. <?php
  2. // Connect to the database
  3. include 'connection.php';
  4.  
  5. // Query for a list of all existing files
  6. $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
  7. $result = mysql_query($sql);
  8.  
  9. // Check if it was successfull
  10. if($result) {
  11. // Make sure there are some files in there
  12. if(mysql_num_rows($result) == 0) {
  13. echo '<p>There are no files in the database</p>';
  14. }
  15. else {
  16. // Print the top of a table
  17. echo '<table width="100%">
  18. <tr>
  19. <td><b>Name</b></td>
  20. <td><b>Mime</b></td>
  21. <td><b>Size (bytes)</b></td>
  22. <td><b>Created</b></td>
  23. <td><b> </b></td>
  24. </tr>';
  25.  
  26. // Print each file
  27. while($row = mysql_fetch_assoc($result)) {
  28. echo "
  29. <tr>
  30. <td>{$row['name']}</td>
  31. <td>{$row['mime']}</td>
  32. <td>{$row['size']}</td>
  33. <td>{$row['created']}</td>
  34. <td><a href='index.php?go=get_file&id={$row['id']}'>Download</a></td>
  35. </tr>";
  36. }
  37.  
  38. // Close table
  39. echo '</table>';
  40. }
  41.  
  42.  
  43. }
  44. else
  45. {
  46. echo 'Error! SQL query failed:';
  47. echo "<pre>{mysql_error}</pre>";
  48. }
  49.  
  50. ?>

get_file.php (w tym jest błąd :/)
  1. <?php
  2. // Make sure an ID was passed
  3. if(isset($_GET['id'])) {
  4. // Get the ID
  5. $id = intval($_GET['id']);
  6.  
  7. // Make sure the ID is in fact a valid ID
  8. if($id <= 0) {
  9. die('The ID is invalid!');
  10. }
  11. else {
  12. // Connect to the database
  13. include 'connection.php';
  14.  
  15.  
  16. // Fetch the file information
  17. $query = "
  18. SELECT `mime`, `name`, `size`, `data`
  19. FROM `file`
  20. WHERE `id` = {$id}";
  21. $result = mysql_query($query);
  22.  
  23. if($result) {
  24. // Make sure the result is valid
  25. if(mysql_num_rows($result) == 1) {
  26. // Get the row
  27. $row = mysql_fetch_assoc($result);
  28.  
  29. // Print headers
  30. header("Content-Type: ". $row['mime']);
  31. header("Content-Length: ". $row['size']);
  32. header("Content-Disposition: attachment; filename=". $row['name']);
  33.  
  34. // Print data
  35. echo $row['data'];
  36. }
  37. else {
  38. echo 'Error! No image exists with that ID.';
  39. }
  40.  
  41. }
  42. else {
  43. echo "Error! Query failed: <pre>{mysql_error}</pre>";
  44. }
  45. }
  46. }
  47. else {
  48. echo 'Error! No ID was passed.';
  49. }
  50. ?>


index.php
  1. <?php
  2. // zmienna potrzebna do prawidlowego wczytania includowanych plikow
  3. $add_site = true;
  4. ?>
  5. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  6. <html>
  7. <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
  8. <meta http-equiv="Reply-to" content="kess@snug.pl" />
  9. <meta name="Author" content="Krzysztof Szypulski" />
  10. <head>
  11. <title>Strona Kuby P.</title>
  12. <style type="text/css">
  13. <!--
  14.  
  15. body {
  16. font-family: Verdana, Arial;
  17. font-size: 12px;
  18. }
  19.  
  20. -->
  21. </style>
  22. </head>
  23. <body>
  24. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  25. <tr>
  26. <td width="100%" colspan="3"><?php include "include/naglowek.php"; ?></td>
  27. </tr>
  28. <tr>
  29. <td width="15%" valign="top"><?php include "include/menu_lewe.php"; ?></td>
  30. <td width="70%" valign="top">
  31. <?php
  32. // zmienna $go przekazana metoda GET
  33. $go = $_GET['go'];
  34.  
  35. // sprawdzamy czy zmienna $go nie jest pusta
  36. if(!empty($go)) {
  37. // sprawdzamy czy plik o danej nazwie istnieje
  38. if(is_file("page/$go.php")) include "page/$go.php";
  39. // jezeli plik nie istnieje wyswietla się komunikat
  40. else echo "<br />Nie ma takiej strony :-(";
  41. }
  42. // jezeli zmienna $go jest pusta wyswietla się strona glowna
  43. else include "page/start.html";
  44.  
  45. ?>
  46. </td>
  47. <td width="15%" valign="top"><?php include "include/menu_prawe.php"; ?></td>
  48. </tr>
  49. <tr>
  50. <td width="100%" colspan="3"><?php include "include/stopka.php"; ?></td>
  51. </tr>
  52. </table>
  53. </body>
  54. </html>


Baaardzo proszę o pomoc i dzięki z góry!
Daiquiri
Nawet nie zerknąłeś w wyszukiwarkę (czy to na forum, czy po prostu w google). Polecam hasło "headers already sent". Zamykam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.