Thursday, June 21, 2012

Create a Zip Archive File Using PHP


Today we are going to program, How to build a Zip Archive from the Entire Directory or Create Zip file from selected file from server. Here is the solution to Create Zip file with PHP

Following PHP Program you can build Zip file
1 . Zip Entire Directory
2.  Zip Selected Files







<?php

include_once("CreateZipFile.inc.php");
$createZipFile=new CreateZipFile;

$directoryToZip="./";
$outputDir="/";
$zipName="CreateZipFileWithPHP.zip";

define("ZIP_DIR",1); // Make it 0 to Archive selected file(s)

if(ZIP_DIR)
{
//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);
}else
{
 $fileToZip1="files/File1.txt";
 $fileToZip2="files/File2.txt";
 $createZipFile->addFile(file_get_contents($fileToZip1),$fileToZip1);
 $createZipFile->addFile(file_get_contents($fileToZip2),$fileToZip2);
 $createZipFile->addFile(file_get_contents($fileToZip3),$fileToZip3);
}

$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@unlink($zipName);
?>


Download This Script     Download Script    

Monday, June 11, 2012

redirect with WWW htaccess





If you need to redirect your domain name with "WWW" you can use the following htaccess code for Apache based web servers.


Redirect with WWW htaccess



Options +FollowSymLinks
RewriteEngine On

# Mention Domain name

RewriteCond %{HTTP_HOST} ^example.com [NC]
Rewriterule ^(.*)$ http://www.example.com/$1 [R=301,NC]

# OR
# get domain name automatically.

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]