Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Wednesday, October 13, 2010

How to synchronize MySQL time with server time?

This command

SET GLOBAL time_zone = 'SYSTEM';

If you can edit my.cnf file, set MySQL default timezone with this line

[mysqld]
default-time-zone='SYSTEM'

How to save progressive JPEG with GD Library?



PHP imageinterlace() funtion turns the interlace bit on or off.
If the interlace bit is set and the image is used as a JPEG image, the image is created as a progressive JPEG.

<?php
// Create an image instance
$im = imagecreatefromjpeg('test.jpg');

// Enable interlancing
imageinterlace($im, true);

// Save the interlaced image
imagegif($im, './progressive.jpg');
imagedestroy($im);
?>

How to [recursively] Zip a directory in PHP?

You can Zip a directory with ZipArchive Class in PHP easily.


<?php
function archive($path, $archive, $pathcleaning = false){
$zip = new ZipArchive();
if ($zip->open($archive, ZIPARCHIVE::CREATE) !== TRUE) {  die ("Could not open archive");  }
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($iterator as $key=>$value) 
if(basename($key) != '.' && basename($key) != '..'){
$zip->addFile(realpath($key), $pathcleaning ? str_replace($path, '', $key) : $key) or die ("ERROR: Could not add file: $key");
}
$zip->close();
}


// zip a directory
archive('data/', 'data.zip', true);


// get the zip file
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="data.zip"');
header('Content-Transfer-Encoding: binary');
readfile('data.zip');
?>

How to create subdomains using htaccess?

First, you should set all subdomains to one directory in your web server config.

like this one below: 
ServerName  mydomain.com
ServerAlias   *.mydomain.com
Second, add this code to your .htacess file

RewriteEngine on
# SUB DOMAINS
RewriteCond %{http_host} !www\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteCond %{http_host} ^(www.)?([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteRule (.*) /clients/%2/$1 [L]
# /SUB DOMAINS 


Finally, you should create a /clients/ folder in the main directory. Now every folder under /clients/ folder is a subdomain
For ex. If you have a test/ folder under the /clients/ folder, you can call the folder test.mydomain.com