Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z pętlą foreach, Dziekuje za pomoc.
emi1
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 29.02.2012

Ostrzeżenie: (0%)
-----


Witam, bardzo proszę was o pomoc gdy probuję ocenić zdjęcie lub dodać komentarz wywala :

  1. Warning: Invalid argument supplied for foreach() in /home/testowon/domains/strona.pl/public_html/lib/cache.php on line 53
  2.  
  3. Warning: Invalid argument supplied for foreach() in /home/testowon/domains/strona.pl/public_html/lib/cache.php on line 57
  4.  
  5. Warning: Cannot modify header information - headers already sent by (output started at /home/testowon/domains/strona.pl/public_html/lib/cache.php:53) in /home/testowon/domains/strona.pl/public_html/index.php on line 137


Kod pliku cache.php:

  1. <?php
  2.  
  3. /*
  4. The Cache class reads and writes complete pages from the cache.
  5. The name of a cache file is based on its URL
  6. */
  7.  
  8. class Cache {
  9. private $fileName = '';
  10. private $path = '';
  11. private $enabled = true;
  12. private $captured = false;
  13.  
  14. public function __construct( $path, $pageName ) {
  15. $this->path = $path;
  16. $this->fileName = $this->path . strtr( $pageName, '?&', '--' ) . '.html';
  17.  
  18. if( $_SERVER['REQUEST_METHOD'] != 'GET' ) {
  19. $this->enabled = false;
  20. }
  21. }
  22.  
  23. public function disable() {
  24. $this->enabled = false;
  25. }
  26.  
  27. public function forceEnable() {
  28. $this->enabled = true;
  29. }
  30.  
  31. public function lookup() {
  32. if( $this->enabled && file_exists($this->fileName) ) {
  33. $fp = fopen($this->fileName, 'rb');
  34. fpassthru($fp);
  35. fclose($fp);
  36. exit();
  37. }
  38. }
  39.  
  40. public function capture() {
  41. if( $this->enabled ) {
  42. $this->captured = true;
  43. }
  44. }
  45.  
  46. public function clear( $pattern = '' ) {
  47. require_once( 'lib/filesystem.php' );
  48. if( empty($pattern) && !empty($this->path) ) {
  49. Filesystem::rmdirr( $this->path, true );
  50. } else {
  51. $files = glob( $this->path . 'all/view/' . strtr( $pattern, '?&', '--' ) . '.html' );
  52. foreach( $files as $f ) {
  53. unlink( $f );
  54. }
  55. $files = glob( $this->path . 'user/*/view/' . strtr( $pattern, '?&', '--' ) . '.html' );
  56. foreach( $files as $f ) {
  57. unlink( $f );
  58. }
  59. }
  60. }
  61.  
  62. public function write() {
  63. if( $this->captured ) {
  64. require_once( 'lib/filesystem.php' );
  65. Filesystem::mkdirr( dirname($this->fileName) );
  66. file_put_contents( $this->fileName, ob_get_contents() );
  67. }
  68. }
  69. }
  70.  
  71. ?>



Ktos wie jak to naprawić?

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Uriziel01
post
Post #2





Grupa: Zarejestrowani
Postów: 307
Pomógł: 37
Dołączył: 9.11.2010
Skąd: Zielona Góra

Ostrzeżenie: (0%)
-----


Pomiędzy linią 52 a 53 zrób var dump'a z zmiennej $files,z pewnościa nie ma tam tablicy.
Go to the top of the page
+Quote Post
Sephirus
post
Post #3





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Wykorzystana funkcja glob() zwraca tablice plików, pustą tablicę lub FALSE w przypadku błędu... Normalnym założeniem jest, że żaden rodzaj tablicy nie popsuje pętli foreach więc na bank funkcja ta zwraca false czyli pokićkałeś coś w tych adresach/ścieżkach albo jest coś nie tak z przekazywana do metody zmienną $pattern

EDIT: Poza tym

Cytat
On some systems it is impossible to distinguish between empty match and an error.


Najlepszym rozwiązaniem będzie sprawdzenie dokładne tych ścieżek - a także sprawdź czy skrypt przeszukujący te ścieżki - ma do nich uprawnienia odczytu - bo ta funkcja też może wywalać false w momencie gdy nie ma uprawnień odczytu...

Ten post edytował Sephirus 29.02.2012, 09:35:18


--------------------
If you're good at something, never do it for free.
Potrzebujesz skryptu JS lub PHP - szukasz kogoś kto przetestuje twoją aplikację pod względem bezpieczeństwa? Szybko i solidnie? Napisz ;)
Mój blog - Jak zwiększyć wydajność front-endu - O buforowaniu wyjścia w PHP słów kilka...
Go to the top of the page
+Quote Post
emi1
post
Post #4





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 29.02.2012

Ostrzeżenie: (0%)
-----


Dzięki chłopaki za zainteresowanie wink.gif

Po dodaniu vad dump'a pokazało te same błędy tyle że w pierwszej lini "bool(false)".

Po tym jak owe błędy pokażą się i wróce na strone następnie oswieże to komentarz który dodalem wczesniej jest normalnie wyswietlony razem z ocena.





Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 17:59