Location: PHPKode > scripts > Zip Folder > zip-folder/documentation/__filesource/fsource_ZipFolder__ZipFolder.php.html
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>File Source for ZipFolder.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
						
<h1>Source for file ZipFolder.php</h1>
<p>Documentation is available at <a href="../ZipFolder/_ZipFolder_php.html">ZipFolder.php</a></p>
<div class="src-code">
<pre><ol><li><a name="a1"></a><span class="src-php">&lt;?php</span></li>
<li><a name="a2"></a><span class="src-doc">/**</span></li>
<li><a name="a3"></a><span class="src-doc"> * ZipFolder, PHP5 zip folder class</span></li>
<li><a name="a4"></a><span class="src-doc"> * </span></li>
<li><a name="a5"></a><span class="src-doc"> * This class allows for an OOP approach to reading zip folders. This class</span></li>
<li><a name="a6"></a><span class="src-doc"> * was written for use on Microsoft Windows based machine using the ZZIPlib</span></li>
<li><a name="a7"></a><span class="src-doc"> * library.</span></li>
<li><a name="a8"></a><span class="src-doc"> * </span></li>
<li><a name="a9"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@author</span><span class="src-doc"> Robert Guerin &lt;hide@address.com&gt;</span></li>
<li><a name="a10"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> 1.0</span></li>
<li><a name="a11"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> ZipFolder</span></li>
<li><a name="a12"></a><span class="src-doc"> */</span></li>
<li><a name="a13"></a>&nbsp;</li>
<li><a name="a14"></a><span class="src-key">class </span><a href="../ZipFolder/ZipFolder.html">ZipFolder</a> <span class="src-sym">{</span></li>
<li><a name="a15"></a>    </li>
<li><a name="a16"></a>    <span class="src-key">private </span><span class="src-var">$loadPath</span><span class="src-sym">;</span></li>
<li><a name="a17"></a>    <span class="src-key">private </span><span class="src-var">$savePath</span><span class="src-sym">;</span></li>
<li><a name="a18"></a>    <span class="src-key">private </span><span class="src-var">$file</span><span class="src-sym">;</span></li>
<li><a name="a19"></a>    <span class="src-key">private </span><span class="src-var">$folder</span><span class="src-sym">;</span></li>
<li><a name="a20"></a>&nbsp;</li>
<li><a name="a21"></a>     <span class="src-doc">/**</span></li>
<li><a name="a22"></a><span class="src-doc">     * Sets the path to the zip file being read.</span></li>
<li><a name="a23"></a><span class="src-doc">     *</span></li>
<li><a name="a24"></a><span class="src-doc">     * $loadPath must be the complete path to the file being read,</span></li>
<li><a name="a25"></a><span class="src-doc">     * including a trailing &quot;\&quot;.  This is the path only the filename</span></li>
<li><a name="a26"></a><span class="src-doc">     * must be set through the setFile() method.</span></li>
<li><a name="a27"></a><span class="src-doc">     *</span></li>
<li><a name="a28"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setFile()</span></li>
<li><a name="a29"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$loadPath </span></li>
<li><a name="a30"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a31"></a><span class="src-doc">     */</span></li>
<li><a name="a32"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../ZipFolder/ZipFolder.html#methodsetLoadPath">setLoadPath</a><span class="src-sym">(</span><span class="src-var">$loadPath</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a33"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">loadPath </span>= <span class="src-var">$loadPath</span><span class="src-sym">;</span></li>
<li><a name="a34"></a>    <span class="src-sym">}</span></li>
<li><a name="a35"></a>    </li>
<li><a name="a36"></a>     <span class="src-doc">/**</span></li>
<li><a name="a37"></a><span class="src-doc">     * Returns the path to the zip file being read.</span></li>
<li><a name="a38"></a><span class="src-doc">     *</span></li>
<li><a name="a39"></a><span class="src-doc">     * If the path is not set through the setLoadPath() method the</span></li>
<li><a name="a40"></a><span class="src-doc">     * path defaults to the directory the script is called from.</span></li>
<li><a name="a41"></a><span class="src-doc">     * </span></li>
<li><a name="a42"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setLoadPath()</span></li>
<li><a name="a43"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span></li>
<li><a name="a44"></a><span class="src-doc">     */</span></li>
<li><a name="a45"></a>    <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">getLoadPath</span><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a46"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">loadPath </span>== <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a47"></a>            <span class="src-var">$path </span>= <a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;/&quot;</span><span class="src-sym">, </span><span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'SCRIPT_FILENAME'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a48"></a>            <a href="http://www.php.net/array_pop">array_pop</a><span class="src-sym">(</span><span class="src-var">$path</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a49"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">loadPath </span>= <a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">&quot;/&quot;</span><span class="src-sym">, </span><span class="src-var">$path</span><span class="src-sym">)</span>.<span class="src-str">&quot;/&quot;</span><span class="src-sym">;</span></li>
<li><a name="a50"></a>        <span class="src-sym">}</span></li>
<li><a name="a51"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">loadPath</span><span class="src-sym">;</span></li>
<li><a name="a52"></a>    <span class="src-sym">}</span></li>
<li><a name="a53"></a>&nbsp;</li>
<li><a name="a54"></a>     <span class="src-doc">/**</span></li>
<li><a name="a55"></a><span class="src-doc">     * Sets the path to the where the zip folder contents will be saved.</span></li>
<li><a name="a56"></a><span class="src-doc">     *</span></li>
<li><a name="a57"></a><span class="src-doc">     * $savePath must be the complete path to the file being read,</span></li>
<li><a name="a58"></a><span class="src-doc">     * including a trailing &quot;\&quot;.  This is the path only the folder</span></li>
<li><a name="a59"></a><span class="src-doc">     * where the contents are saved has the same name as the zip folder</span></li>
<li><a name="a60"></a><span class="src-doc">     * unless specified through the setFolder() method.</span></li>
<li><a name="a61"></a><span class="src-doc">     *</span></li>
<li><a name="a62"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setFolder()</span></li>
<li><a name="a63"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$savePath </span></li>
<li><a name="a64"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a65"></a><span class="src-doc">     */</span></li>
<li><a name="a66"></a>    <span class="src-key">public </span><span class="src-key">Function </span><a href="../ZipFolder/ZipFolder.html#methodsetSavePath">setSavePath</a><span class="src-sym">(</span><span class="src-var">$savePath</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a67"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">savePath </span>= <span class="src-var">$savePath</span><span class="src-sym">;</span></li>
<li><a name="a68"></a>    <span class="src-sym">}</span></li>
<li><a name="a69"></a>    </li>
<li><a name="a70"></a>     <span class="src-doc">/**</span></li>
<li><a name="a71"></a><span class="src-doc">     * Returns the path to the where the zip file contents will be saved.</span></li>
<li><a name="a72"></a><span class="src-doc">     *</span></li>
<li><a name="a73"></a><span class="src-doc">     * If the path is not set through the setSavePath() method the</span></li>
<li><a name="a74"></a><span class="src-doc">     * path defaults to the directory the script is called from.</span></li>
<li><a name="a75"></a><span class="src-doc">     * </span></li>
<li><a name="a76"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setSavePath</span></li>
<li><a name="a77"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span></li>
<li><a name="a78"></a><span class="src-doc">     */    </span></li>
<li><a name="a79"></a>     <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a80"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">savePath </span>== <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a81"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">savePath </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getLoadPath</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a82"></a>        <span class="src-sym">}</span></li>
<li><a name="a83"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">savePath</span><span class="src-sym">;</span></li>
<li><a name="a84"></a>    <span class="src-sym">}</span></li>
<li><a name="a85"></a>&nbsp;</li>
<li><a name="a86"></a>     <span class="src-doc">/**</span></li>
<li><a name="a87"></a><span class="src-doc">     * Sets the name of the zip file.</span></li>
<li><a name="a88"></a><span class="src-doc">     *</span></li>
<li><a name="a89"></a><span class="src-doc">     * $file is the name of the zip file to be read.  The path to the</span></li>
<li><a name="a90"></a><span class="src-doc">     * file must be set through the setLoadPath() method</span></li>
<li><a name="a91"></a><span class="src-doc">     *</span></li>
<li><a name="a92"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setLoadPath()</span></li>
<li><a name="a93"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$file </span></li>
<li><a name="a94"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a95"></a><span class="src-doc">     */    </span></li>
<li><a name="a96"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../ZipFolder/ZipFolder.html#methodsetFile">setFile</a><span class="src-sym">(</span><span class="src-var">$file</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a97"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">file </span>= <span class="src-var">$file</span><span class="src-sym">;</span></li>
<li><a name="a98"></a>        <span class="src-var">$path </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getLoadPath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">file</span><span class="src-sym">;</span></li>
<li><a name="a99"></a>        <span class="src-var">$file_array </span>= <a href="http://www.php.net/pathinfo">pathinfo</a><span class="src-sym">(</span><span class="src-var">$path</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a100"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$file_array</span><span class="src-sym">[</span><span class="src-str">'extension'</span><span class="src-sym">] </span>== <span class="src-str">'zip'</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a101"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">folder </span>= <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$file</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span>-<span class="src-sym">(</span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$file_array</span><span class="src-sym">[</span><span class="src-str">'extension'</span><span class="src-sym">]</span><span class="src-sym">)</span>+<span class="src-num">1</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a102"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a103"></a>            throw <span class="src-key">new </span><span class="src-id">Exception</span><span class="src-sym">(</span><span class="src-str">'The file must be a Zip folder'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a104"></a>        <span class="src-sym">}</span></li>
<li><a name="a105"></a>    <span class="src-sym">}</span></li>
<li><a name="a106"></a>&nbsp;</li>
<li><a name="a107"></a>    <span class="src-doc">/**</span></li>
<li><a name="a108"></a><span class="src-doc">     * Returns the name of the zip file.</span></li>
<li><a name="a109"></a><span class="src-doc">     * </span></li>
<li><a name="a110"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span></li>
<li><a name="a111"></a><span class="src-doc">     */</span></li>
<li><a name="a112"></a>    <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">getFile</span><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a113"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">file</span><span class="src-sym">;</span></li>
<li><a name="a114"></a>    <span class="src-sym">}</span></li>
<li><a name="a115"></a>&nbsp;</li>
<li><a name="a116"></a>    <span class="src-doc">/**</span></li>
<li><a name="a117"></a><span class="src-doc">     * Sets the name of the folder where the zip file contents</span></li>
<li><a name="a118"></a><span class="src-doc">     * will be written.</span></li>
<li><a name="a119"></a><span class="src-doc">     *</span></li>
<li><a name="a120"></a><span class="src-doc">     * $folder is the name of the folder where the zip file contents</span></li>
<li><a name="a121"></a><span class="src-doc">     * will be be written. If the name is not specified, the name of the</span></li>
<li><a name="a122"></a><span class="src-doc">     * folder will be the same as the zip file</span></li>
<li><a name="a123"></a><span class="src-doc">     *</span></li>
<li><a name="a124"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$folder </span></li>
<li><a name="a125"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a126"></a><span class="src-doc">     */</span></li>
<li><a name="a127"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../ZipFolder/ZipFolder.html#methodsetFolder">setFolder</a><span class="src-sym">(</span><span class="src-var">$folder</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a128"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">folder </span>= <span class="src-var">$folder</span><span class="src-sym">;</span></li>
<li><a name="a129"></a>    <span class="src-sym">}</span></li>
<li><a name="a130"></a>&nbsp;</li>
<li><a name="a131"></a>    <span class="src-doc">/**</span></li>
<li><a name="a132"></a><span class="src-doc">     * Returns the name of the folder where the zip file contents</span></li>
<li><a name="a133"></a><span class="src-doc">     * will be written.</span></li>
<li><a name="a134"></a><span class="src-doc">     * </span></li>
<li><a name="a135"></a><span class="src-doc">     * If the name is not specified through the setFolder() method the</span></li>
<li><a name="a136"></a><span class="src-doc">     * name of the folder will be the same as the zip file</span></li>
<li><a name="a137"></a><span class="src-doc">     * </span></li>
<li><a name="a138"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setFolder()</span></li>
<li><a name="a139"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span></li>
<li><a name="a140"></a><span class="src-doc">     */</span></li>
<li><a name="a141"></a>    <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a142"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">folder</span><span class="src-sym">;</span></li>
<li><a name="a143"></a>    <span class="src-sym">}</span></li>
<li><a name="a144"></a>&nbsp;</li>
<li><a name="a145"></a>    <span class="src-doc">/**</span></li>
<li><a name="a146"></a><span class="src-doc">     * Recursive method to delete directories</span></li>
<li><a name="a147"></a><span class="src-doc">     * </span></li>
<li><a name="a148"></a><span class="src-doc">     * $directory is the path and name of the folder to delete. Such as</span></li>
<li><a name="a149"></a><span class="src-doc">     * &quot;C:/This/Is/A/Test/&quot; where &quot;Test&quot; is the folder to be deleted.</span></li>
<li><a name="a150"></a><span class="src-doc">     * This is a recursive function to delete directories and all</span></li>
<li><a name="a151"></a><span class="src-doc">     * sub-directories and files.</span></li>
<li><a name="a152"></a><span class="src-doc">     * </span></li>
<li><a name="a153"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$directory </span></li>
<li><a name="a154"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a155"></a><span class="src-doc">     */</span></li>
<li><a name="a156"></a>    <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">removeDirectory</span><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a157"></a>       <span class="src-var">$directory_contents </span>= <a href="http://www.php.net/scandir">scandir</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a158"></a>       <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$directory_contents </span><span class="src-key">as </span><span class="src-var">$item</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a159"></a>           <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_dir">is_dir</a><span class="src-sym">(</span><span class="src-var">$directory</span>.<span class="src-var">$item</span><span class="src-sym">) </span>&amp;&amp; <span class="src-var">$item </span>!= <span class="src-str">'.' </span>&amp;&amp; <span class="src-var">$item </span>!= <span class="src-str">'..'</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a160"></a>               <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">removeDirectory</span><span class="src-sym">(</span><span class="src-var">$directory</span>.<span class="src-var">$item</span>.<span class="src-str">'/'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a161"></a>           <span class="src-sym">}</span></li>
<li><a name="a162"></a>           <span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/file_exists">file_exists</a><span class="src-sym">(</span><span class="src-var">$directory</span>.<span class="src-var">$item</span><span class="src-sym">) </span>&amp;&amp; <span class="src-var">$item </span>!= <span class="src-str">'.' </span>&amp;&amp; <span class="src-var">$item </span>!= <span class="src-str">'..'</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a163"></a>               <a href="http://www.php.net/unlink">unlink</a><span class="src-sym">(</span><span class="src-var">$directory</span>.<span class="src-var">$item</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a164"></a>           <span class="src-sym">}</span></li>
<li><a name="a165"></a>       <span class="src-sym">}</span></li>
<li><a name="a166"></a>       <a href="http://www.php.net/rmdir">rmdir</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a167"></a>   <span class="src-sym">} </span></li>
<li><a name="a168"></a>&nbsp;</li>
<li><a name="a169"></a>    <span class="src-doc">/**</span></li>
<li><a name="a170"></a><span class="src-doc">     * Recursive method to create directories</span></li>
<li><a name="a171"></a><span class="src-doc">     * </span></li>
<li><a name="a172"></a><span class="src-doc">     * $directory is the path and name of the folder to create. Such as</span></li>
<li><a name="a173"></a><span class="src-doc">     * &quot;C:/This/Is/A/Test/&quot; where &quot;Test&quot; is the folder to be created.</span></li>
<li><a name="a174"></a><span class="src-doc">     * This is a recursive function to create directories and all</span></li>
<li><a name="a175"></a><span class="src-doc">     * sub-directories and files.</span></li>
<li><a name="a176"></a><span class="src-doc">     * </span></li>
<li><a name="a177"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc"> </span><span class="src-doc-type">string </span><span class="src-doc">       </span><span class="src-doc-var">$directory </span></li>
<li><a name="a178"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a179"></a><span class="src-doc">     */</span></li>
<li><a name="a180"></a>    <span class="src-key">private </span><span class="src-key">function </span><span class="src-id">makeDirectories</span><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">, </span><span class="src-var">$recursive </span>= <span class="src-id">true</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a181"></a>          <span class="src-key">if</span><span class="src-sym">( </span><a href="http://www.php.net/is_null">is_null</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">) </span>|| <span class="src-var">$directory </span>=== <span class="src-str">&quot;&quot; </span><span class="src-sym">)</span><span class="src-sym">{</span></li>
<li><a name="a182"></a>               <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a183"></a>          <span class="src-sym">}</span></li>
<li><a name="a184"></a>        <span class="src-key">if</span><span class="src-sym">( </span><a href="http://www.php.net/is_dir">is_dir</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">) </span>|| <span class="src-var">$directory </span>=== <span class="src-str">&quot;c:/&quot; </span><span class="src-sym">)</span><span class="src-sym">{</span></li>
<li><a name="a185"></a>            <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a186"></a>        <span class="src-sym">}</span></li>
<li><a name="a187"></a>        <span class="src-key">if</span><span class="src-sym">( </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">makeDirectories</span><span class="src-sym">(</span><a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-var">$recursive</span><span class="src-sym">) )</span><span class="src-sym">{</span></li>
<li><a name="a188"></a>             <span class="src-key">return </span><a href="http://www.php.net/mkdir">mkdir</a><span class="src-sym">(</span><span class="src-var">$directory</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a189"></a>        <span class="src-sym">}</span></li>
<li><a name="a190"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a191"></a>    <span class="src-sym">} </span></li>
<li><a name="a192"></a>&nbsp;</li>
<li><a name="a193"></a>    <span class="src-doc">/**</span></li>
<li><a name="a194"></a><span class="src-doc">     * This method actually uncompresses the zip folder and</span></li>
<li><a name="a195"></a><span class="src-doc">     * saves its contents to the specefied directory.</span></li>
<li><a name="a196"></a><span class="src-doc">     * </span></li>
<li><a name="a197"></a><span class="src-doc">     * This method actually uncompresses the zip folder and</span></li>
<li><a name="a198"></a><span class="src-doc">     * saves its contents to the specefied directory.  The</span></li>
<li><a name="a199"></a><span class="src-doc">     * path and file where the contents are saved is set</span></li>
<li><a name="a200"></a><span class="src-doc">     * through the setSavePath() and setFolder() methods.</span></li>
<li><a name="a201"></a><span class="src-doc">     * </span></li>
<li><a name="a202"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setSavePath()</span></li>
<li><a name="a203"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> setFolder()</span></li>
<li><a name="a204"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">boolean </span></li>
<li><a name="a205"></a><span class="src-doc">     */</span></li>
<li><a name="a206"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../ZipFolder/ZipFolder.html#methodopenZip">openZip</a><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a207"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$zip </span>= <span class="src-id">zip_open</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getLoadPath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFile</span><span class="src-sym">(</span><span class="src-sym">))) </span><span class="src-sym">{</span></li>
<li><a name="a208"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$zip</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a209"></a>                <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_dir">is_dir</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-str">&quot;/&quot;</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a210"></a>                    <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">removeDirectory</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-str">&quot;/&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a211"></a>                <span class="src-sym">} </span></li>
<li><a name="a212"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">makeDirectories</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a213"></a>                <span class="src-key">while </span><span class="src-sym">(</span><span class="src-var">$zip_entry </span>= <span class="src-id">zip_read</span><span class="src-sym">(</span><span class="src-var">$zip</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a214"></a>                    <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">zip_entry_open</span><span class="src-sym">(</span><span class="src-var">$zip</span><span class="src-sym">,</span><span class="src-var">$zip_entry</span><span class="src-sym">,</span><span class="src-str">&quot;r&quot;</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a215"></a>                        <span class="src-var">$buf </span>= <span class="src-id">zip_entry_read</span><span class="src-sym">(</span><span class="src-var">$zip_entry</span><span class="src-sym">, </span><span class="src-id">zip_entry_filesize</span><span class="src-sym">(</span><span class="src-var">$zip_entry</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a216"></a>                        <span class="src-var">$directory_name </span>= <a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span><span class="src-id">zip_entry_name</span><span class="src-sym">(</span><span class="src-var">$zip_entry</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a217"></a>                        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$directory_name </span>!= <span class="src-str">&quot;.&quot;</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a218"></a>                            <span class="src-var">$dir_op </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-str">&quot;/&quot;</span><span class="src-sym">;</span></li>
<li><a name="a219"></a>                            <span class="src-key">foreach </span><span class="src-sym">( </span><a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;/&quot;</span><span class="src-sym">,</span><span class="src-var">$directory_name</span><span class="src-sym">) </span><span class="src-key">as </span><span class="src-var">$k</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a220"></a>                                <span class="src-var">$dir_op </span>= <span class="src-var">$dir_op </span>. <span class="src-var">$k</span><span class="src-sym">;</span></li>
<li><a name="a221"></a>                                <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_file">is_file</a><span class="src-sym">(</span><span class="src-var">$dir_op</span><span class="src-sym">)) </span><a href="http://www.php.net/unlink">unlink</a><span class="src-sym">(</span><span class="src-var">$dir_op</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a222"></a>                                 <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_dir">is_dir</a><span class="src-sym">(</span><span class="src-var">$dir_op</span><span class="src-sym">)) </span><a href="http://www.php.net/mkdir">mkdir</a><span class="src-sym">(</span><span class="src-var">$dir_op</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a223"></a>                                 <span class="src-var">$dir_op </span>= <span class="src-var">$dir_op </span>. <span class="src-str">&quot;/&quot; </span><span class="src-sym">;</span></li>
<li><a name="a224"></a>                             <span class="src-sym">}</span></li>
<li><a name="a225"></a>                        <span class="src-sym">}</span></li>
<li><a name="a226"></a>                <span class="src-var">$fp</span>=<a href="http://www.php.net/fopen">fopen</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getSavePath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFolder</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-str">&quot;/&quot;</span>.<span class="src-id">zip_entry_name</span><span class="src-sym">(</span><span class="src-var">$zip_entry</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-str">&quot;w&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a227"></a>                <a href="http://www.php.net/fwrite">fwrite</a><span class="src-sym">(</span><span class="src-var">$fp</span><span class="src-sym">,</span><span class="src-var">$buf</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a228"></a>                   <a href="http://www.php.net/fclose">fclose</a><span class="src-sym">(</span><span class="src-var">$fp</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a229"></a>                <span class="src-id">zip_entry_close</span><span class="src-sym">(</span><span class="src-var">$zip_entry</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a230"></a>                   <span class="src-sym">} </span><span class="src-key">else</span></li>
<li><a name="a231"></a>                       <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a232"></a>                   <span class="src-sym">}</span></li>
<li><a name="a233"></a>                   <span class="src-id">zip_close</span><span class="src-sym">(</span><span class="src-var">$zip</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a234"></a>            <span class="src-sym">}</span></li>
<li><a name="a235"></a>        <span class="src-sym">} </span><span class="src-key">else</span></li>
<li><a name="a236"></a>    <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a237"></a>      <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a238"></a>    <span class="src-sym">}</span></li>
<li><a name="a239"></a>&nbsp;</li>
<li><a name="a240"></a>    <span class="src-doc">/**</span></li>
<li><a name="a241"></a><span class="src-doc">     * This method deletes the zip file</span></li>
<li><a name="a242"></a><span class="src-doc">     * </span></li>
<li><a name="a243"></a><span class="src-doc">     * This method deletes the zip file.  If called it must</span></li>
<li><a name="a244"></a><span class="src-doc">     * be called after the openZip() method.</span></li>
<li><a name="a245"></a><span class="src-doc">     * </span></li>
<li><a name="a246"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@see</span><span class="src-doc"> openZip()</span></li>
<li><a name="a247"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">boolean </span></li>
<li><a name="a248"></a><span class="src-doc">     */</span></li>
<li><a name="a249"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../ZipFolder/ZipFolder.html#methoderaseZip">eraseZip</a><span class="src-sym">(</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a250"></a>        <a href="http://www.php.net/unlink">unlink</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getLoadPath</span><span class="src-sym">(</span><span class="src-sym">)</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getFile</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a251"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a252"></a>    <span class="src-sym">}</span></li>
<li><a name="a253"></a><span class="src-sym">}</span></li>
</ol></pre>
</div>
	<p class="notes" id="credit">
		Documentation generated on Thu, 06 Jul 2006 23:02:25 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.3.0RC3</a>
	</p>
	</body>
</html>
Return current item: Zip Folder