<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-603755190363040920</id><updated>2012-02-16T15:40:33.280-08:00</updated><title type='text'>php source code</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://php-source-code.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/603755190363040920/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://php-source-code.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>bala</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-603755190363040920.post-8298075764375826371</id><published>2012-01-10T21:55:00.000-08:00</published><updated>2012-01-11T05:03:14.233-08:00</updated><title type='text'>zip and unzip files using php</title><content type='html'>&lt;pre&gt;&lt;br /&gt;&lt;span class='subtitle'&gt;Create Zip Files Using PHP&lt;/span&gt;&lt;br /&gt;&lt;span class='sourcecode'&gt;SourceCode&lt;br /&gt;$zip=new ZipArchive();&lt;br /&gt;$destination=DIRDetails."/filename.zip";&lt;br /&gt;if($zip-&gt;open($destination,ZIPARCHIVE::CREATE) !== true) {&lt;br /&gt;   return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;foreach($doclist as $thefile)&lt;br /&gt;{&lt;br /&gt;   $random=rand(11111,99999);&lt;br /&gt;   $filename=$random.$thefile;      &lt;br /&gt;   $zip-&gt;addFile($thefile-&gt;tempname,$filename);&lt;br /&gt;}&lt;br /&gt;$zip-&gt;close();   &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;span class='subtitle'&gt;Extract Zip Files Using PHP&lt;/span&gt;&lt;br /&gt;&lt;span class='sourcecode'&gt;SourceCode&lt;br /&gt;$filename='filename';     &lt;br /&gt;$zipfile=DirDetails."/filename.zip";   &lt;br /&gt;$zip = zip_open($zipfile);&lt;br /&gt;$extract=DirDetails."/newfolder";        &lt;br /&gt;if ($zip) &lt;br /&gt;{    &lt;br /&gt;    if(!is_dir($extract))&lt;br /&gt;         mkdir($extract);  &lt;br /&gt;    while ($zip_entry = zip_read($zip)) {&lt;br /&gt; // if(zip_entry_name($zip_entry)==$filename)&lt;br /&gt; //if you need any specified file use this condition&lt;br /&gt;    {                    &lt;br /&gt;      $fp = fopen($extract."/".zip_entry_name($zip_entry), "w");                &lt;br /&gt;      if (zip_entry_open($zip, $zip_entry, "r")) {&lt;br /&gt;         $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));&lt;br /&gt;         fwrite($fp,"$buf");&lt;br /&gt;         zip_entry_close($zip_entry);&lt;br /&gt;         fclose($fp);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   zip_close($zip);&lt;br /&gt;  }&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class='subtitle'&gt;Download Zip Files Using PHP&lt;/span&gt;&lt;br /&gt;&lt;span class='sourcecode'&gt;SourceCode&lt;br /&gt;&lt;br /&gt; public function downloadfinal($docid,$docname)&lt;br /&gt;    {&lt;br /&gt;        $filename=Dirdetails"filename.zip"; &lt;br /&gt;        if(file_exists($filename)){&lt;br /&gt;            $path_parts = pathinfo($filename); &lt;br /&gt;            $ext = strtolower($path_parts["extension"]); &lt;br /&gt;            switch ($ext) &lt;br /&gt;            { &lt;br /&gt;              case "pdf": $ctype="application/pdf"; break; &lt;br /&gt;              case "exe": $ctype="application/octet-stream"; break; &lt;br /&gt;              case "zip": $ctype="application/zip"; break; &lt;br /&gt;              case "doc": $ctype="application/msword"; break; &lt;br /&gt;              case "xls": $ctype="application/vnd.ms-excel"; break; &lt;br /&gt;              case "ppt": $ctype="application/vnd.ms-powerpoint"; break; &lt;br /&gt;              case "gif": $ctype="image/gif"; break; &lt;br /&gt;              case "png": $ctype="image/png"; break; &lt;br /&gt;              case "jpg": $ctype="image/jpg"; break; &lt;br /&gt;              default: $ctype="application/force-download"; &lt;br /&gt;            } &lt;br /&gt;            $newpath=$extract.'/'.$filename;    &lt;br /&gt;            header("Pragma: public");&lt;br /&gt;            header("Content-Type: application/$ctype");&lt;br /&gt;            header("Content-Disposition: inline; filename=$docname");&lt;br /&gt;            header('Content-Length: '.filesize($filename));&lt;br /&gt;            header("Accept Ranges: bytes");&lt;br /&gt;            header("Expires: 0"); &lt;br /&gt;            header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); &lt;br /&gt;            readfile("$filename");&lt;br /&gt;        }&lt;br /&gt;       else&lt;br /&gt;       {&lt;br /&gt;        echo "error";&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/hr/&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class='subtitle'&gt;Delete Zip Files Using PHP&lt;/span&gt;&lt;br /&gt;&lt;span class='sourcecode'&gt;SourceCode&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/603755190363040920-8298075764375826371?l=php-source-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-source-code.blogspot.com/feeds/8298075764375826371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://php-source-code.blogspot.com/2012/01/zip-and-unzip-files-using-php.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/603755190363040920/posts/default/8298075764375826371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/603755190363040920/posts/default/8298075764375826371'/><link rel='alternate' type='text/html' href='http://php-source-code.blogspot.com/2012/01/zip-and-unzip-files-using-php.html' title='zip and unzip files using php'/><author><name>bala</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
