Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Nieprawidłowe nazy plików po utworzeniu ZIPa
JamalBIG
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Witam

Poniżej przesyłam kod tworzący plik ZIP, niestety, po jego rozpakowaniu programem 7Zip okazuje się, że na końcu każdego pliku jest '_' (podkreślnik). Sprawdziłem dokładnie nazy w poleceniu 'addFile' ale tam wszystko jest ok, również pliki które są pakowane wyglądają ok - czy może to być wina serwera czy problem jest ze skryptem?

Z góry dzięki za pomoc

  1. public function create_zip($files = array(), $destination = '', $overwrite = false)
  2. {
  3.  
  4. //if the zip file already exists and overwrite is false, return false
  5. if(file_exists($destination) && !$overwrite) { return false; }
  6.  
  7. //vars
  8. $valid_files = array();
  9. //if files were passed in...
  10. if(is_array($files)) {
  11. //cycle through each file
  12. foreach($files as $file) {
  13. //make sure the file exists
  14. if(file_exists($file)) {
  15. $valid_files[] = $file;
  16. }
  17. }
  18. }
  19.  
  20. //if we have good files...
  21. if(count($valid_files)) {
  22. //create the archive
  23. $zip = new ZipArchive();
  24. if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
  25. return false;
  26. }
  27. //add the files
  28. foreach($valid_files as $file)
  29. {
  30. #echo dirname(__FILE__).'/../../'.$file.', '.basename($file).PHP_EOL.'<br />';
  31. $zip->addFile($file, basename($file).PHP_EOL);
  32. }
  33.  
  34. //debug
  35. #echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
  36.  
  37. //close the zip -- done!
  38. $zip->close();
  39.  
  40. //check to make sure the file exists
  41. return file_exists($destination);
  42. }
  43. else
  44. {
  45. return false;
  46. }
  47. }
Go to the top of the page
+Quote Post
Xelah
post
Post #2





Grupa: Zarejestrowani
Postów: 139
Pomógł: 24
Dołączył: 12.05.2013
Skąd: Hamburg

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


A możesz wyjaśnić co robi PHP_EOL przy dodawaniu do archiwum?
Go to the top of the page
+Quote Post
JamalBIG
post
Post #3





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Przeszkadza w poprawnym funkcjonowaniu skryptu biggrin.gif
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: 22.08.2025 - 00:00