Category Archives: PHP

PHP

Create a floder zip programatically in php

If we are working on live or demo project, it’s very important to take a back up of project in every day.

Suppose we want to take a back up of server files than it will take more time to transfer all files and folder from FTP. but if create programatically zip of projects than we can easily download it.

Create a floder zip programatically, zip in php, create zip file in php, backup zip in magento, magento backup zip script


<?php 

// var_dump( extension_loaded('zip') ); // Extension Zip is loaded or not

$the_folder = '/var/www/html/BACKUP-FOLDERNAME'; // Location which we want to zip
$zip_file_name = '/var/www/html/backup.zip';  // Location where we keep zip folder 
 
$za = new FlxZipArchive;
 
$res = $za->open($zip_file_name, ZipArchive::CREATE);
 
if($res === TRUE) {
    $za->addDir($the_folder, basename($the_folder));
    $za->close();
	echo '<p>Check if the zip file is created now!</p>';
}
else{
    echo 'Could not create a zip archive';
}

class FlxZipArchive extends ZipArchive {
/**
* Add a Dir with Files and Subdirs to the archive
*
* @param string $location Real Location
* @param string $name Name in Archive
* @author Nicolas Heimann
* @access private
**/
 
public function addDir($location, $name) {
$this->addEmptyDir($name);
 
$this->addDirDo($location, $name);
} // EO addDir;
 
/**
* Add Files & Dirs to archive.
*
* @param string $location Real Location
* @param string $name Name in Archive
* @author Nicolas Heimann
* @access private
**/
 
private function addDirDo($location, $name) {
$name .= '/';
$location .= '/';
 
// Read all Files in Dir
$dir = opendir ($location);
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..') continue;
 
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, $name . $file);
}
} // EO addDirDo();
}
?>

How to check curl version in php

Using curl_version we want to see curl version any many other features of curl in php.

<?php
        
// Get curl version array
$version = curl_version();

echo '<pre>';
print_r($version);
echo'</pre>';



echo 'Output is ====>'.'<br/>';
?>

Array
(
    [version_number] => 467712
    [age] => 3
    [features] => 50877
    [ssl_version_number] => 0
    [version] => 7.35.0
    [host] => x86_64-pc-linux-gnu
    [ssl_version] => OpenSSL/1.0.1f
    [libz_version] => 1.2.8
    [protocols] => Array
        (
            [0] => dict
            [1] => file
            [2] => ftp
            [3] => ftps
            [4] => gopher
            [5] => http
            [6] => https
            [7] => imap
            [8] => imaps
            [9] => ldap
            [10] => ldaps
            [11] => pop3
            [12] => pop3s
            [13] => rtmp
            [14] => rtsp
            [15] => smtp
            [16] => smtps
            [17] => telnet
            [18] => tftp
        )

)

How to check curl installed or not Click Here

How to check curl installed or not

It’s easy to check in php that curl is installed or not.

<?php
        // ### Checks for presence of the cURL extension.
function _isCurlInstalled() {
	if  (in_array  ('curl', get_loaded_extensions())) {
		return true;
	}
	else{
		return false;
	}
}

if (_isCurlInstalled()){
 echo "cURL is installed";
} else{
 echo "cURL is NOT installed";
}

exit;

?>

How to check curl version in php Click Here