dulldusk / phpfm

phpFileManager is a complete filesystem management tool on a single file. This is a tool meant for rapid file access, and also to verify the server php configuration and security. The script can be renamed and deployed on an unique known url, and offers password protection.
https://sourceforge.net/projects/phpfm/
Other
216 stars 98 forks source link

zipped folders accompanied by extra files with the same name #27

Open beccare opened 5 years ago

beccare commented 5 years ago

When I zip nested directories on Linux shared hosting with PHP 7.3., I cannot unzip them after download to Windows 10 (e.g. with 7z). The zip archives contain one extra file for every folder with the same name. These files get extracted first - to 0-byte files - after which the folders cannot be extracted because the files with the same name are in their way.

It is probably related to some basics of Linux/Windows file system representation - but, unfortunately, I have no time to dive into that. In the meantime, I'll just work around with time-consuming unzipped folder downloads via FTP - but maybe other people would know what to do about it?

Here a small example with a zipped version of the file structure:

dir example
--dir a
----hello.txt
--dir b

http://stahl-electronics.com/frank/example.zip

ungenio commented 5 years ago

I have the same problem, too. To compress a directory I'm using another script. It is fast and does not generate corrupt files.

`<?php $the_folder = 'NAME FOLDER HERE'; $zip_filename = "backup".date('Y-m-d_His').".zip"; // name of the returned file

$download_file= true; //$delete_file_after_download= true; doesnt work!!

class FlxZipArchive extends ZipArchive { / Add a Dir with Files and Subdirs to the archive;;;;; @param string $location Real Location;;;; @param string $name Name in Archive;;; @author Nicolas Heimann;;;; @access private /

public function addDir($location, $name) {
    $this->addEmptyDir($name);

    $this->addDirDo($location, $name);
 } // EO addDir;

/**  Add Files & Dirs to archive;;;; @param string $location Real Location;  @param string $name Name in Archive;;;;;; @author Nicolas Heimann
 * @access private   **/
private function addDirDo($location, $name) {
    $name .= '/';
    $location .= '/';

    // Read all Files in Dir
    $dir = opendir ($location);
    while ($file = readdir($dir))
    {
        if ($file == '.' || $file == '..') continue;
        // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
        $do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
        $this->$do($location . $file, $name . $file);
    }
} // EO addDirDo();

}

$za = new FlxZipArchive; $res = $za->open($zip_file_name, ZipArchive::CREATE); if($res === TRUE) { $za->addDir($the_folder, basename($the_folder)); $za->close(); } else { echo 'Could not create a zip archive';}

if ($download_file) { ob_get_clean(); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=" . basename($zip_file_name) . ";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($zip_file_name)); readfile($zip_file_name); } ?>`

It is necessary to write the name of the folder

$the_folder = 'NAME FOLDER HERE';

It would be great if this code could be incorporated into PHPFM.

dulldusk commented 4 years ago

Thanks for the notice beccare, this is a great issue. I have yet to test phpFileManager better on the latest php versions. But nobody make donations to the project, so the process is very slow. I thanks ungenio too for the code, it surely can be tested and incorporated on the script, if it is indeed a solution. Why don't you update the script and make a pull request? I will gladly test it, accept it, and then your name will be forever on the changelog as a contributor. https://www.dulldusk.com/phpfm/changelog/

atesin commented 4 years ago

sadly with this bug i cant use this software yet :( ..... copying massive files (zipped) from and to the website is an essential feature for an online file manager :(((

i tried to patch myself but i am not so skilled and is very hard to me :( .... i hope somebody will pull a patch soon, even with code above (can i subscribe?) ....

arnisjuraga commented 4 years ago

Windows file system usually is case-insensitive. Linux on the other hand is case-sensitive. So, adding files

my_images
|- image.jpeg
|- Image.jpeg 
|- image.JPEG

will have 3 "similar" filenames which are completely OK on Linux file system, but will generate error "file already exists" when extracted on Windows system.

I am not saying this is the reason in this time, but double checking zipped files might helped for anyone landing to this issue by search.

atesin commented 4 years ago

in reply to @arnisjuraga , conventionally all filenames in web server document root should be lowercase

in reply to me, there are native php extensions that can be used instead: zip, bzip2, gzip

atesin commented 3 years ago

hi, is there some update on this? ... i think this is a critical issue... until maybe there are others more critical i didnt read

some bug reports even come with patch... please read them and dont lose the oportunity of people that are helping to improve this good piece of software

atesin commented 2 years ago

hi.... any news about this?

.... a year has passed ... is this project still alive? ... would be ashame if not, i like it so much, but this is a huge annoyance because i cant be downloading a big populated folder one file at a time... or even worse whole directory trees :(

JoyBrad commented 2 years ago

@dulldusk @atesin @beccare Unfortunately, I had to spend a few days to get the downloaded zip fixed. It will be cumbersome to fix manually if the zip has many folders/files.

Fortunately, I did not do all that manually and had some time to spend so created a shell script that works like a charm and fixes the issues observed so far in the zip created by phpfm.

Code: fix-duplicate-names-in-zip.sh

Hope it helps for the time being until the issue is fixed by phpfm.

Also, the issue is still there in the latest version 1.7.9. I might contribute to fix this in phpfm itself if I get some time.

atesin commented 2 years ago

hi... thanks for your care ... 3 ideas come to my mind

JoyBrad commented 2 years ago

@atesin I have not dived into the phpfm code yet, but I think it should be pretty simple to fix in php as you suggest using native functions.

I don't think it's a good idea to use the shell script as a part of phpfm. Besides, the script works only for .zip files for now. I noticed that the problem is same or similar for each of the compression methods offered by phpfm. So in that sense, a php fix might be little trickier as well. Not if someone figures out the cause of the behavior. The script is just a workaround till the time it's fixed in phpfm, at least you can backup your contents in zip and be able to view/extract after fixing it.

Also, let me know if you tested it and if it works fine.

JoyBrad commented 2 years ago

By looking at the zip, the cause seems to me that the Zip file may have been created(by phpfm) without dedicated directory entries. For instance the zip tool has the option -D do not add directory entries.

atesin commented 2 years ago

if the problem is similar for all compression methods, then i think all methods are managed by the same (bugged) external library.... so by dropping the external library in favor of standard ones will kill all problems at once..... additionally, "official" libraries got "official" support

JoyBrad commented 2 years ago

@atesin Seems like phpfm uses pack() function to write the zip as binary, and using magic numbers like 0x04034b50 for zip. and 0x02014b50 for zip_dir_magic_number. Only someone who wrote it should and can fix it properly since I don't want to spend hours understanding and testing different scenarios to find the logical error.

Until then, going to use my shell script to fix it post-download