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. |
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 | |
/** | |
* 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 | |
/** | |
* 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 | |
// 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 | |
/** | |
* Finds whether a variable is a unsigned float or a numeric string. | |
* Sometimes, we need to have no letters in the number and is_numeric does not quit the job. | |
* @param string The variable being evaluated. | |
* @link http://php.net/manual/en/function.is-numeric.php#47491 | |
* @return 1|emptystring It returns 1 if okay and returns nothing "" if it's bad number formating | |
* @since 11/6/14 11:15 AM | |
*/ | |
function isUnsignedFloat($val) { |
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 | |
/** | |
* This function performs an HTTP POST request to a specified URL with given parameters. | |
* | |
* @param string $url The URL to which the POST request is sent. | |
* @param array $params An associative array containing the POST parameters as key-value pairs. | |
* @param string $referer The referer header for the request. | |
* | |
* @return mixed The response from the HTTP POST request. | |
*/ |
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 | |
/** | |
* Detect Mobile Browsers | |
* @link http://detectmobilebrowsers.com/ | |
* @return boolean | |
*/ | |
static function idMobileBrowser() { | |
$useragent = $_SERVER['HTTP_USER_AGENT']; | |
if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', | |
$useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad| |
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 | |
/** | |
* Retuns client's IP address | |
* @return string | |
* @since 6/16/11 12:11 PM | |
*/ | |
function getClientIPAddress() { | |
if (getenv("HTTP_CLIENT_IP")) { | |
$ip = getenv("HTTP_CLIENT_IP"); | |
} else { |
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 | |
/** | |
* IP to long | |
* @param type $ip | |
* @return int | |
*/ | |
function ipToLong($ip = false) { | |
if (!$ip) { | |
$ip = getClientIPAddress(); | |
} |
OlderNewer