This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Define a function named humanlyFileSize that takes two parameters: | |
// $bytes - the file size in bytes | |
// $decimals (optional) - the number of decimal places to include in the result (default is 2) | |
function humanlyFileSize($bytes, $decimals = 2) { | |
// Define a string $sz containing the size suffixes for bytes (B), kilobytes (K), megabytes (M), | |
// gigabytes (G), terabytes (T), and petabytes (P). | |
$sz = 'BKMGTP'; | |
// Calculate the appropriate size suffix based on the file size in bytes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copy a file, or recursively copy a folder and its contents | |
* | |
* @author Aidan Lister <[email protected]> | |
* @version 1.0.1 | |
* @link http://aidanlister.com/2004/04/recursively-copying-directories-in-php/ | |
* @param string $source Source path | |
* @param string $dest Destination path | |
* @return bool Returns TRUE on success, FALSE on failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Format a given number of bytes into a human-readable string with specified precision. | |
* | |
* @param int|float $bytes The number of bytes to format. | |
* @param int $precision The number of decimal places for precision (default is 2). | |
* | |
* @return string The formatted string representing the bytes with appropriate units (e.g., KB, MB, GB). | |
*/ | |
function formatBytes($bytes, $precision = 2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to extract a YouTube video ID from a given URL. | |
* | |
* @param string $url The input URL that may contain a YouTube video link. | |
* | |
* @return string|false If a YouTube video ID is found, it is returned; otherwise, false is returned. | |
*/ | |
function getYoutubeVideoIdFromUrl($url) { | |
// Regular expression to match YouTube video URLs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check if the 'zip' parameter is empty in the GET request. | |
if(empty($_GET['zip'])){ | |
// If 'zip' parameter is empty, terminate the script and display 'No zip!' message. | |
die('No zip!'); | |
} | |
// Create a new instance of the ZipArchive class. | |
$zip = new ZipArchive; | |
// Try to open the zip file specified in the 'zip' parameter. |
NewerOlder