Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem ze skryptem. Szukam pomocy
Konkordzik
post 19.01.2020, 19:12:49
Post #1





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

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


Witam. Próbowałem przetworzyć pliki ale wyskakuje mi to:

Warning: fwrite() expects parameter 1 to be resource, string given in /usr/local/www/apache24/data/patch/index.php on line 15
Warning: fclose() expects parameter 1 to be resource, string given in /usr/local/www/apache24/data/patch/index.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache24/data/patch/index.php:15) in /usr/local/www/apache24/data/patch/index.php on line 17


Trzymajcie kawałek skryptu. Możesz ktoś pomożesz naprawić to.

  1. <?php
  2. $files_list = 'lista_plikow';
  3. $rebuild_list = 'przebuduj_liste';
  4.  
  5. define('_DIR', getcwd());
  6. if (isset($_GET[$rebuild_list]))
  7. {
  8. $files = get_dir(_DIR . '/files');
  9. $list = '';
  10. foreach ($files as $file)
  11. {
  12. $list .= substr($file, 1) . ';' . strtoupper(md5_file(_DIR . '/files/' . $file)) . "\n";
  13. }
  14. $f = @fopen(_DIR . '/files/._files', 'w+');
  15. fwrite($f, trim($list));
  16. fclose($f);
  17. header( 'Location: index.php?'.$files_list);
  18. } elseif (isset($_GET[$files_list])) {
  19. ?>




Dzięki wam z góry

Ten post edytował Konkordzik 19.01.2020, 19:14:13
Go to the top of the page
+Quote Post
ohm
post 19.01.2020, 19:30:58
Post #2





Grupa: Zarejestrowani
Postów: 618
Pomógł: 143
Dołączył: 22.12.2010

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


Masz przeciez napisane jak byk

Cytat
expects parameter 1 to be resource, string given


wiec sprawdz co siedzi w $f (wywalajac @ w fopen bedziesz mial moze cos jeszcze)
Go to the top of the page
+Quote Post
Konkordzik
post 19.01.2020, 20:01:48
Post #3





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

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


Cytat(ohm @ 19.01.2020, 19:30:58 ) *
Masz przeciez napisane jak byk



wiec sprawdz co siedzi w $f (wywalajac @ w fopen bedziesz mial moze cos jeszcze)

Za bardzo się na tym nie znam. Dlatego pytam i proszę o pomoc. Wcześniej mi działało a przeniosłem na inną maszynę i zaczyna błąd wywalać.

W całości wygląda tak:

  1. <?php
  2. $files_list = 'lista_plikow';
  3. $rebuild_list = 'przebuduj_liste';
  4.  
  5. define('_DIR', getcwd());
  6. if (isset($_GET[$rebuild_list]))
  7. {
  8. $files = get_dir(_DIR . '/files');
  9. $list = '';
  10. foreach ($files as $file)
  11. {
  12. $list .= substr($file, 1) . ';' . strtoupper(md5_file(_DIR . '/files/' . $file)) . "\n";
  13. }
  14. $f = @fopen(_DIR . '/files/._files', 'w+');
  15. fwrite($files_list, trim($files_list));
  16. fclose($files_list);
  17. header( 'Location: index.php?'.$files_list);
  18. } elseif (isset($_GET[$files_list])) {
  19. ?>
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  22. </head>
  23. <body>
  24. <div style="width: 1200px; text-align: center; margin: auto; font-family: Tahoma;">
  25. <div style="margin: 20px; text-align: center; font-size: 48px;">
  26. <a href="index.php?<?php echo $rebuild_list; ?>">NAZWA GŁÓWNA</a>
  27. </div><hr/>
  28. <?php
  29. $list = trim(file_get_contents(_DIR . '/files/._files'));
  30. $list = explode("\n", $list);
  31. foreach ($list as &$element)
  32. $element = explode(';', $element, 2);
  33. foreach ($list as &$element)
  34. {
  35. ?>
  36. <div style="float: left; width: 400px;">
  37. <div style="width: 400px; float: left;">
  38. <?php echo $element[0]; ?>
  39. </div>
  40. <div style="width: 400px; float: left; margin-bottom: 20px;">
  41. <?php echo $element[1]; ?>
  42. </div>
  43. </div>
  44. <?php
  45. }
  46. ?>
  47. </div>
  48. </body>
  49. <?php
  50. }
  51. function get_dir($dir)
  52. {
  53. $result = array();
  54. $it = new RecursiveDirectoryIterator($dir);
  55. foreach(new RecursiveIteratorIterator($it) as $file) {
  56. if ($file->getFileName() == '.') { continue; }
  57. if ($file->getFileName() == '..') { continue; }
  58. if ($file->getFileName() == '._files') { continue; }
  59. $f = $file->getPath() . '/' . $file->getFileName();
  60. $f = str_replace($dir, '', $f);
  61. $result[] = $f;
  62. }
  63. return $result;
Go to the top of the page
+Quote Post
dublinka
post 19.01.2020, 20:17:47
Post #4





Grupa: Zarejestrowani
Postów: 594
Pomógł: 66
Dołączył: 22.02.2008
Skąd: Dublin

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


  1. $files_list = 'lista_plikow';


widzisz roznice ?

  1. $f = @fopen(_DIR . '/files/._files', 'w+');
  2. fwrite($files_list, trim($files_list));
  3. fclose($files_list);


Skoro uchwytem do fopen jest $f to slkad ci sie bierze w fwrite $files_list ktory jest zwyklym stringiem.
I jeszcze ten string "zamykasz"

  1. $f = @fopen(_DIR . '/files/._files', 'w+');
  2. fwrite($f, "cos do zapisu");
  3. fclose($f);


Ten post edytował dublinka 19.01.2020, 20:19:00


--------------------
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 Wersja Lo-Fi Aktualny czas: 19.04.2024 - 22:12