0

When users want to unzip files on my PHP site(hosting uses Ubuntu 16.04), it works for Linux or MAC users, but does not work for Windows users and just upload zip file without unpacking. I used these solutions:

echo exec("unzip $file_name ",$result, $returnval );
or
$zip = new ZipArchive; $res = $zip->open($file_name); $zip->extractTo($dir); $zip->close();

and also tested PclZip library
$archive = new PclZip($file_name); $result = $archive->extract(PCLZIP_OPT_PATH, $dir);

Eugene
  • 61
  • 1
  • 4
  • Do you even have a command line app called "unzip" on your Windows PC? If so, is it in the path that the web server runs with? In the second example, does the web server process have write permission on `$dir`? – Greg Schmidt Dec 20 '18 at 18:02
  • Run `phpinfo()` to determine if you have the zip extension installed. – Alex Howansky Dec 20 '18 at 18:22
  • it is code on my web hosting (it uses ubuntu 16.04) and when users unzip file on my site ( if they have MAC or Linux) it works, but for Windows users just upload zip on site without unpacking – Eugene Dec 20 '18 at 18:39
  • Are you getting any errors? Define "does not work"? You need to describe how you are 'zipping' the files. If you used the same identical file, the client OS should not factor. I assume this is more about how file is compressed. – ficuscr Dec 20 '18 at 18:46
  • I tested on different laptops one zip file that I downloaded from my Gmail, and it unpacked from my laptop on Ubuntu and not unpacked from a laptop on windows. I used chrome both – Eugene Dec 20 '18 at 18:56
  • That doesn't tell us much... pkzip is pkzip on whatever OS. Are you using `deflate` someplace instead? Remember zip is not the same as zlib or gzip. Don't get gmail in the mix, dirties it, they don't even allow zip attachments if I recall. [Read this](https://stackoverflow.com/questions/19120676/how-to-detect-type-of-compression-used-on-the-file-if-no-file-extension-is-spe). – ficuscr Dec 20 '18 at 19:03

1 Answers1

1

Solved! Windows and Linux browsers send different file type: $_FILES['file']['type'] In Linux browser it is "application/zip", but in windows 'application/x-zip-compressed' I use condition where I check file type. Thanks all who tried to help me.

Eugene
  • 61
  • 1
  • 4