Showing posts with label PHP Script. Show all posts
Showing posts with label PHP Script. Show all posts
Tuesday, November 14, 2017
Create ZIP file with PHP
This is a script to create zip file containing different files. PHP has a ZipArchive class which can be used easily to create zip files.
In this post we will learn how to create zip files in PHP. We will create zip files from different files.
// defined an array with names of files
$files = array('audio1.wav', 'audio2.wav', 'audio3.wav', , 'img1.png', 'img2.jpg');
// the name of zip archive
$zipname = 'file.zip';
//create ner class for zip
$zip = new ZipArchive;
//create new zip
$zip->open($zipname, ZipArchive::CREATE);
//make a loop for adding files into zip file
foreach ($files as $file) {
$zip->addFile($file);
}
//close zip
$zip->close();
This script is about creating zip file in PHP in the same location (folder). If we have different files we must defined the full location of files.
$files = array('./folder1/audio1.wav', './folder1/audio2.wav', './folder7/audio3.wav', 'img1.png', 'img2.jpg');
Monday, January 30, 2017
Move all file from a folder to another PHP
// Get array of all source files into source_folder
$files = scandir("source_folder");
// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
If we want to copy all files from a folder to another follow this URL; http://programming-scripts.blogspot.com/2017/01/copy-all-file-from-folder-to-another-php.html
$files = scandir("source_folder");
// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
If we want to copy all files from a folder to another follow this URL; http://programming-scripts.blogspot.com/2017/01/copy-all-file-from-folder-to-another-php.html
Copy all file from a folder to another PHP
// Get array of all source files into source_folder
$files = scandir("source_folder");
// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
copy($source.$file, $destination.$file);
}
}
If we want to transfer all files from a folder to another follow this URL: http://programming-scripts.blogspot.com/2017/01/move-all-file-from-folder-to-another-php.html
PHP function that return char of column on excel by number
Function that return column char of excel using on PHP programming. Call the function with the number that you want to fund the Char of column
//this function return the char of column from number
function column_char_from_nr($num) {
$numeric = ($num - 1) % 26;
$letter = chr(65 + $numeric);
$num2 = intval(($num - 1) / 26);
if ($num2 > 0) {
return getNameFromNumber($num2) . $letter;
} else {
return $letter;
}
}
For example:
$nr = 5;
$char= column_char_from_nr($nr);
echo "The char of column in excel for number = ".$nr." is <b>".$char."</b>";
// return E
//A B C D E F G ......
//1 2 3 4 5 6 7 ......
Subscribe to:
Posts (Atom)




