简体   繁体   中英

PHP unzip file on the site

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM