{"id":3486,"date":"2018-09-18T03:57:54","date_gmt":"2018-09-18T03:57:54","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=3486"},"modified":"2021-01-13T10:01:32","modified_gmt":"2021-01-13T10:01:32","slug":"extract-zip-gzip-rar-archive-file-using-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/","title":{"rendered":"Extract ZIP File using PHP"},"content":{"rendered":"<p>The archive files are used for data compression. The ZIP, Gzip, and RAR are the commonly used file format to archive files. Generally, we use computer software to extract archive files (ZIP, Gzip, RAR, etc.). But, the archive file also can be extracted on the fly using PHP. You can easily <a href=\"https:\/\/www.codexworld.com\/create-zip-file-using-php\/\">create ZIP file<\/a> dynamically and extract ZIP file from the script with PHP.<\/p>\n<p>The ZipArchive class provides an easy way to extract the archive contents in PHP. You can extract the ZIP file on the server using ZipArchive in PHP. In this tutorial, we will show you how to <b>extract the ZIP file in PHP<\/b>. Not only the ZIP file but also the other archive files (GZIP and RAR) can be extracted in PHP using our example code snippets.<\/p>\n<p>To make the archive extraction process simple, we have grouped all the code in a PHP class and created a custom library named Extractor. This library provides an instant and structured way to implement file extract functionality in PHP.<\/p>\n<h2>Extractor Class<\/h2>\n<p>The Extractor class helps to extract archive files (zip\/gzip\/rar) on the server using PHP ZipArchive.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>extract()<\/b> &#8211; This function checks the extension of the given file and calls the suitable extractor function.\n<ul>\n<li><code>$archive<\/code> &#8211; Relative path of the archive file to be extracted.<\/li>\n<li><code>$destination<\/code> &#8211; The location where to extract files.<\/li>\n<\/ul>\n<\/li>\n<li><b>extractZipArchive()<\/b> &#8211; It is a helper function of Extractor class. This function decompress or extract a ZIP archive file (.zip) using ZipArchive in PHP.<\/li>\n<li><b>extractGzipFile()<\/b> &#8211; It is a helper function of Extractor class. This function decompress or extract a Gzip archive file (.gz) using gzread() in PHP.<\/li>\n<li><b>extractRarArchive()<\/b> &#8211; It is a helper function of Extractor class. This function decompress or extract a RAR archive file (.rar) using RarArchive in PHP.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php<br \/><\/span><span style=\"color: #FF8000\">\/**<br \/>&nbsp;*&nbsp;Class&nbsp;Extractor<br \/>&nbsp;*<br \/>&nbsp;*&nbsp;Extract&nbsp;a&nbsp;archive&nbsp;(zip\/gzip\/rar)&nbsp;file.<br \/>&nbsp;*&nbsp;<br \/>&nbsp;*&nbsp;@author&nbsp;CodexWorld<br \/>&nbsp;*&nbsp;@url&nbsp;https:\/\/www.codexworld.com<br \/>&nbsp;*&nbsp;<br \/>&nbsp;*\/<br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">Extractor&nbsp;<\/span><span style=\"color: #007700\">{<br \/><br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/**<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Checks&nbsp;file&nbsp;extension&nbsp;and&nbsp;calls&nbsp;suitable&nbsp;extractor&nbsp;functions.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$archive<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$destination<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;static&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">extract<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ext&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">pathinfo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">PATHINFO_EXTENSION<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(<\/span><span style=\"color: #0000BB\">$ext<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #DD0000\">'zip'<\/span><span style=\"color: #007700\">:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$res&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">self<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">extractZipArchive<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #DD0000\">'gz'<\/span><span style=\"color: #007700\">:\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$res&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">self<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">extractGzipFile<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #DD0000\">'rar'<\/span><span style=\"color: #007700\">:\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$res&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">self<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">extractRarArchive<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">$res<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/**<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Decompress\/extract&nbsp;a&nbsp;zip&nbsp;archive&nbsp;using&nbsp;ZipArchive.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$archive<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$destination<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;static&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">extractZipArchive<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;webserver&nbsp;supports&nbsp;unzipping.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">class_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'ZipArchive'<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Your&nbsp;PHP&nbsp;version&nbsp;does&nbsp;not&nbsp;support&nbsp;unzip&nbsp;functionality.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$zip&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">ZipArchive<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;archive&nbsp;is&nbsp;readable.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(<\/span><span style=\"color: #0000BB\">$zip<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">open<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">)&nbsp;===&nbsp;<\/span><span style=\"color: #0000BB\">TRUE<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;destination&nbsp;is&nbsp;writable<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(<\/span><span style=\"color: #0000BB\">is_writeable<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$destination&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'\/'<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$zip<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">extractTo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$zip<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">close<\/span><span style=\"color: #007700\">();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'success'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Files&nbsp;unzipped&nbsp;successfully'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Directory&nbsp;not&nbsp;writeable&nbsp;by&nbsp;webserver.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Cannot&nbsp;read&nbsp;.zip&nbsp;archive.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/**<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Decompress&nbsp;a&nbsp;.gz&nbsp;File.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$archive<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$destination<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;static&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">extractGzipFile<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;zlib&nbsp;is&nbsp;enabled<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">function_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'gzopen'<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Error:&nbsp;Your&nbsp;PHP&nbsp;has&nbsp;no&nbsp;zlib&nbsp;support&nbsp;enabled.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$filename&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">pathinfo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">PATHINFO_FILENAME<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$gzipped&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">gzopen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"rb\"<\/span><span style=\"color: #007700\">);\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$file&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">fopen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$filename<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"w\"<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(<\/span><span style=\"color: #0000BB\">$string&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">gzread<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$gzipped<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">4096<\/span><span style=\"color: #007700\">))&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">fwrite<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">strlen<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$string<\/span><span style=\"color: #007700\">));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">gzclose<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$gzipped<\/span><span style=\"color: #007700\">);\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">fclose<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$file<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;file&nbsp;was&nbsp;extracted.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(<\/span><span style=\"color: #0000BB\">file_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'\/'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$filename<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'success'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'File&nbsp;unzipped&nbsp;successfully.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Error&nbsp;unzipping&nbsp;file.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/**<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Decompress\/extract&nbsp;a&nbsp;Rar&nbsp;archive&nbsp;using&nbsp;RarArchive.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$archive<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;$destination\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;static&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">extractRarArchive<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;webserver&nbsp;supports&nbsp;unzipping.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!<\/span><span style=\"color: #0000BB\">class_exists<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'RarArchive'<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Your&nbsp;PHP&nbsp;version&nbsp;does&nbsp;not&nbsp;support&nbsp;.rar&nbsp;archive&nbsp;functionality.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;archive&nbsp;is&nbsp;readable.<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(<\/span><span style=\"color: #0000BB\">$rar&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">RarArchive<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">open<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archive<\/span><span style=\"color: #007700\">)){\r\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;destination&nbsp;is&nbsp;writable<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">is_writeable<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$destination&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'\/'<\/span><span style=\"color: #007700\">))&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$entries&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$rar<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getEntries<\/span><span style=\"color: #007700\">();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(<\/span><span style=\"color: #0000BB\">$entries&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$entry<\/span><span style=\"color: #007700\">)&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$entry<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">extract<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$destination<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$rar<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">close<\/span><span style=\"color: #007700\">();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'success'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'File&nbsp;extracted&nbsp;successfully.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Directory&nbsp;not&nbsp;writeable&nbsp;by&nbsp;webserver.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Cannot&nbsp;read&nbsp;.rar&nbsp;archive.'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>}<\/span><\/pre>\n<h2>Extract ZIP in PHP<\/h2>\n<p>Use <b>Extractor<\/b> class to extract archive files (ZIP, GZIP, and RAR) to the specified destination using PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Include and initialize the Extractor class.<\/li>\n<li>Specify the path of the archive file (ZIP \/ Gzip \/ RAR) which you want to extract.<\/li>\n<li>Specify the destination to extract the ZIP file on the server.<\/li>\n<li>Call the extract() function of Extractor class.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;and&nbsp;initialize&nbsp;Extractor&nbsp;class<br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'Extractor.class.php'<\/span><span style=\"color: #007700\">;<br \/><\/span><span style=\"color: #0000BB\">$extractor&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Extractor<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Path&nbsp;of&nbsp;archive&nbsp;file<br \/><\/span><span style=\"color: #0000BB\">$archivePath&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'\/path\/to\/archive.zip'<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Destination&nbsp;path<br \/><\/span><span style=\"color: #0000BB\">$destPath&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'\/destination\/dir\/'<\/span><span style=\"color: #007700\">;<br \/><br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Extract&nbsp;archive&nbsp;file<br \/><\/span><span style=\"color: #0000BB\">$extract&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$extractor<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">extract<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$archivePath<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$destPath<\/span><span style=\"color: #007700\">);<br \/><br \/>if(<\/span><span style=\"color: #0000BB\">$extract<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'success'<\/span><span style=\"color: #007700\">];<br \/>}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">$GLOBALS<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'error'<\/span><span style=\"color: #007700\">];<br \/>}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The archive files are used for data compression. The ZIP, Gzip, and RAR are the commonly used file format to archive files. Generally, we use computer software to extract archive files (ZIP, Gzip, RAR, etc.). <\/p>\n","protected":false},"author":1,"featured_media":3489,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[345,132,14,319],"class_list":["post-3486","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-archive","tag-file","tag-php","tag-zip","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Extract ZIP File using PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Extract ZIP File using PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-18T03:57:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-13T10:01:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Extract ZIP File using PHP\",\"datePublished\":\"2018-09-18T03:57:54+00:00\",\"dateModified\":\"2021-01-13T10:01:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/\"},\"wordCount\":359,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/php-extract-zip-gzip-rar-archive-file-codexworld.png\",\"keywords\":[\"Archive\",\"File\",\"PHP\",\"ZIP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/\",\"name\":\"Extract ZIP File using PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/php-extract-zip-gzip-rar-archive-file-codexworld.png\",\"datePublished\":\"2018-09-18T03:57:54+00:00\",\"dateModified\":\"2021-01-13T10:01:32+00:00\",\"description\":\"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/php-extract-zip-gzip-rar-archive-file-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/php-extract-zip-gzip-rar-archive-file-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"php-extract-zip-gzip-rar-archive-file-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/extract-zip-gzip-rar-archive-file-using-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Extract ZIP File using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Extract ZIP File using PHP - CodexWorld","description":"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Extract ZIP File using PHP - CodexWorld","og_description":"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.","og_url":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2018-09-18T03:57:54+00:00","article_modified_time":"2021-01-13T10:01:32+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Extract ZIP File using PHP","datePublished":"2018-09-18T03:57:54+00:00","dateModified":"2021-01-13T10:01:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/"},"wordCount":359,"commentCount":0,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","keywords":["Archive","File","PHP","ZIP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/","url":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/","name":"Extract ZIP File using PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","datePublished":"2018-09-18T03:57:54+00:00","dateModified":"2021-01-13T10:01:32+00:00","description":"Extract ZIP archive - Example code to extract ZIP file using PHP. Use Extractor class to extract archive file (ZIP, Gzip, and RAR) on the server using ZipArchive, gzread, and RarArchive in PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","width":1366,"height":768,"caption":"php-extract-zip-gzip-rar-archive-file-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/extract-zip-gzip-rar-archive-file-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Extract ZIP File using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2018\/09\/php-extract-zip-gzip-rar-archive-file-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-Ue","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=3486"}],"version-history":[{"count":4,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3486\/revisions"}],"predecessor-version":[{"id":4563,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/3486\/revisions\/4563"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/3489"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=3486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=3486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=3486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}