public function getDirSize($dir, $format = true)
{
$dir_iterator = new RecursiveDirectoryIterator($dir);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
$size = 0;
foreach ($iterator as $file) {
$size += $file->getSize();
}
if ($format) {
if ($size / 1048576 > 1) {
return round($size / 1048576, 1) . ' MB';
// if the total size is bigger than 1 KB
} elseif ($size / 1024 > 1) {
return round($size / 1024, 1) . ' KB';
// else return the filesize in bytes
} else {
return round($size, 1) . ' bytes';
}
} else {
// return the total filesize in bytes
return $size;
}
}
usage:
$size = getDirSize('/dir/to/get/size/');
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
function get_currency_rate
Simple, yet effective way to get currency rate from yahoo finance service. Cache the results, or you will get ban from yahoo.
How to check if image has no code injected?
If you let images with code injection be saved on your server, it is possible, that it's a highwayto your php files and whole database, so it is important to make sure, that if user uploads avatar, it is really an avatar, not some hacky stuff with code injected into the image.
php5/ext/pcre/php_pcre.h:29:18: fatal error: pcre.h: No such file or directory while installing php zip
I was trying to use ZipArchive, but i got an error:
Fatal error: Class 'ZipArchive' not foundThen I started to Google how to install zip extension on my Ubuntu Apache 2 server. I have PHP version 5.3.10 and in configuration it says, that zip is enabled. This information you can get with these 2 simple commands:
How to use template engine in Symfony 2?
How to join 2 SQL tables with PHP? Examples and visualisations
Often you need to join data from 2 tables. You can do it with several SQL queries and PHP, or just use JOIN functions. The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables. Most popular joins are INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN. It's always good to know the different.
What is the different between HTML CSS PHP and JavaScript?
HTML - it's like bones for your site. It says what to display on the user's browser: Tables, titles, paragraphs, lists, links etc. It is client-side language which is understood by browsers like Google Chrome, FireFox, Safari.
Subscribe to:
Posts (Atom)





