Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Nagłowiek HTTP a fcja header() - błędy
Forum PHP.pl > Forum > Serwery WWW
bartu$
Witam.

Mam taki skrypt, który działa prawidłowo na jednym serwerze tzn. że sie nie wysypuje i przegladarka otwiera plik w Excelu. Z kolei na innym serwerze skrypt sie nie wysypuje a przegladarka (ta sama,IE), nie potrafi otworzyc pliku ani w zewnetrznym programie (Excel) ani wyswietlic czegokolwiek.

Komunikat, ze "nie moze pobrac. Zadana witryna jest niedostepna lub nie moze jej znalezc". Komunikat jest nie jest wyswietlany na stronie, ale w oknie takim jak przy pobieraniu pliku. Pole typ pliku jest puste.
No a na tym 1szym serwerze w polu jest ze to plik Excel i sie otwiera.

podejrzewam ze chodzi o wysylanie błędnego nagłówka. gdzie to mozna sprawdzic/zmienic questionmark.gif

A oto ten skrypt :

  1. <?
  2. //Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
  3. //pear excel package has support for fonts and formulas etc.. more complicated
  4. //this is good for quick table dumps (deliverables)
  5.  
  6.  
  7. $linkID = mysql_connect('mysql.serwer.pl', 'jakis', 'jakie');
  8. mysql_select_db('baza1701', $linkID);
  9. $result = mysql_query('select * from authtab', $linkID);
  10. $count = mysql_num_fields($result);
  11.  
  12. for ($i = 0; $i < $count; $i++){
  13.     $header .= mysql_field_name($result, $i).&#092;"t\";
  14. }
  15.  
  16. while($row = mysql_fetch_row($result)){
  17.   $line = '';
  18.   foreach($row as $value){
  19.     if(!isset($value) || $value == &#092;"\"){
  20.       $value = &#092;"t\";
  21.     }else{
  22. # important to escape any quotes to preserve them in the data.
  23.       $value = str_replace('\"', '\"\"', $value);
  24. # needed to encapsulate data in quotes because some data might be multi line.
  25. # the good news is that numbers remain numbers in Excel even though quoted.
  26.       $value = '\"' . $value . '\"' . &#092;"t\";
  27.     }
  28.     $line .= $value;
  29.   }
  30.   $data .= trim($line).&#092;"n\";
  31. }
  32. # this line is needed because returns embedded in the data have \"r\"
  33. # and this looks like a \"box character\" in Excel
  34.   $data = str_replace(&#092;"r\", \"\", $data);
  35.  
  36.  
  37. # Nice to let someone know that the search came up empty.
  38. # Otherwise only the column name headers will be output to Excel.
  39. if ($data == &#092;"\") {
  40.   $data = &#092;"nno matching records foundn\";
  41. }
  42.  
  43. # This line will stream the file to the user rather than spray it across the scr
  44. en
  45. header(&#092;"Content-type: application/octet-stream\");
  46.  
  47. # replace excelfile.xls with whatever you want the filename to default to
  48. header(&#092;"Content-Disposition: attachment; filename=excelfile.xls\");
  49. header(&#092;"Pragma: no-cache\");
  50. header(&#092;"Expires: 0\");
  51.  
  52. echo $header.&#092;"n\".$data;
  53. ?>


Prosze o pomoc ekspertów. smile.gif


ps. Próbowałem z ob_start() i ob_end_flush() - ale tez nie dziala sad.gif
Kocurro
może byś skasował pustą linię na początku kodu ?

na jednym serwerze masz php ustawionego tak, że ma buforowanie właczone - dlatego buforuje tą pustą linię i wysyła prawidłowe nagłówki. Na drugi masz buforowanie wyłaczone - dlatego nie może wyśłać nagłówków - do tego nie wyświetla komunikatu o błędzike bo wyświetlanie komunikatów jest wyłączone.

Mam nadzieję, że pomoże smile.gif

Pozdrawiam

ps: wybacz, jeśli niezbyt miło napsiałem odpowiedź winksmiley.jpg
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.