Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]PHP nie widzi pierwszych znaków, Coś zmalowałem
Johnas
post
Post #1





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


Witam, mam problem... mianowicie nie wiem nawet gdzie go szukać... PHP ignoruje mi pierwsze znaki...


  1. $dir = dirname(__FILE__);
  2. $rootPath = realpath('./global');
  3. $zip = new ZipArchive;
  4. $zip->open('update-'.$version.'.zip', ZipArchive::CREATE | ZipArchive::EXCL);
  5.  
  6. $files = new RecursiveIteratorIterator(
  7. new RecursiveDirectoryIterator($rootPath),
  8. RecursiveIteratorIterator::LEAVES_ONLY
  9. );
  10.  
  11. foreach ($files as $name => $file) {
  12. $file_in_zip = str_replace($dir."\\", "", $file)."<br>";
  13. if (!$file->isDir())
  14. {
  15. // Get real and relative path for current file
  16. $filePath = $file->getRealPath();
  17. $relativePath = substr($filePath, strlen($rootPath) + 1);
  18. $path_in_zip = str_replace($dir."\\", "", $filePath);
  19. // Add current file to archive
  20. if (strpos($relativePath, "nstall\\") or strpos($relativePath, "ake-update.php") or strpos($relativePath, "old\\") or strpos($relativePath, "zepsuty") or strpos($relativePath, "lobal\config.php") or strpos($relativePath, "vs\\") or strpos($relativePath, "git\\") or strpos($relativePath, "idea\\") or strpos($relativePath, "pload\\") or strpos($relativePath, "cache\\") or strpos($relativePath, 'ploads\\') or strpos($relativePath, "emplates_c")) {
  21. echo "Ignoruje ".$relativePath."</br>";
  22. } else {
  23. echo "Dodano plik: ".$relativePath."</br>";
  24. $zip->addFile($filePath, $path_in_zip, true);
  25. }
  26. }
  27. }
  28.  
  29. $zip->close();


mam taki kod.. i wszystko dobrze by było gdyby nie to że muszę użyć
  1. strpos($relativePath, "nstall\\")
"nstall" zamiast install, a wszystkie skompresowane pliki nie mają pierwszego znaku... Wie ktoś może co jest przyczyną tego błędu ?
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


A patrzyłeś co otrzymujesz w zmiennej $relativePath?
Go to the top of the page
+Quote Post
Johnas
post
Post #3





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


  1. if (strpos($relativePath, "zepsuty\\")) {
  2. echo $relativePath."< posiada napis zepsuty<br>";
  3. } else {
  4. echo $relativePath."< nie posiada napisu zepsuty<br>";
  5. }

daje wynik
Kod
zepsuty\users.class.php< nie posiada napisu zepsuty
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


strpos zwraca false w przypadku braku ciągu, a Ty tego nie sprawdzasz.
Go to the top of the page
+Quote Post
Johnas
post
Post #5





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


To dlaczego mi kompresuje pliki bez pierwszego znaku we wszystkich plikach ?
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Piszę o tym, że powinieneś sprawdzać czy strpos zwraca false, a tego nie robisz. Ciąg znaków może zaczynać się od pozycji 0, a taką sytuację traktujesz jako fałsz.
Go to the top of the page
+Quote Post
Johnas
post
Post #7





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


Cytat(trueblue @ 20.08.2022, 21:36:50 ) *
strpos zwraca false w przypadku braku ciągu, a Ty tego nie sprawdzasz.



masz rację...

  1. if (strpos($relativePath, "zepsuty\\") !== false) {
  2. echo $relativePath."< posiada napis zepsuty<br>";
  3. } else {
  4. echo $relativePath."< nie posiada napisu zepsuty<br>";
  5. }


Rozwiązuje to jeden problem, ale zip compressuje mi wszystkie pliki bez pierwszego znaku...

Funkcja zip compressuje mi wszystkie pliki bez pierwszego znaku:

  1. ?php
  2. $config = (object) array(
  3. // config
  4. );
  5. ?>


i wszystkie pliki nie mają pierwszego znaku

Ale numer (IMG:style_emoticons/default/biggrin.gif) wiesz że zmiana kodu naprawiła problem (IMG:style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 24.08.2025 - 04:54