clipbucket/upload/actions/include_functions.php
2013-10-07 12:17:06 +00:00

130 lines
3.5 KiB
PHP

<?php
function RandomString($length)
{
// Generate random 32 charecter string
$string = md5(microtime());
// Position Limiting
$highest_startpoint = 32-$length;
// Take a random starting point in the randomly
// Generated String, not going any higher then $highest_startpoint
$randomString = substr($string,rand(0,$highest_startpoint),$length);
return $randomString;
}
function formatfilesize( $data ) {
// bytes
if( $data < 1024 ) {
return $data . " bytes";
}
// kilobytes
else if( $data < 1024000 ) {
return round( ( $data / 1024 ), 1 ) . "KB";
}
// megabytes
else if($data < 1024000000){
return round( ( $data / 1024000 ), 1 ) . " MB";
}else{
return round( ( $data / 1024000000 ), 1 ) . " GB";
}
}
/**
* Function used to get file name
*/
function GetName($file)
{
if(!is_string($file))
return false;
$path = explode('/',$file);
if(is_array($path))
$file = $path[count($path)-1];
$new_name = substr($file, 0, strrpos($file, '.'));
return $new_name;
}
function get_elapsed_time($ts,$datetime=1)
{
if($datetime == 1)
{
$ts = date('U',strtotime($ts));
}
$mins = floor((time() - $ts) / 60);
$hours = floor($mins / 60);
$mins -= $hours * 60;
$days = floor($hours / 24);
$hours -= $days * 24;
$weeks = floor($days / 7);
$days -= $weeks * 7;
$t = "";
if ($weeks > 0)
return "$weeks week" . ($weeks > 1 ? "s" : "");
if ($days > 0)
return "$days day" . ($days > 1 ? "s" : "");
if ($hours > 0)
return "$hours hour" . ($hours > 1 ? "s" : "");
if ($mins > 0)
return "$mins min" . ($mins > 1 ? "s" : "");
return "< 1 min";
}
//Function Used TO Get Extensio Of File
function GetExt($file){
return substr($file, strrpos($file,'.') + 1);
}
function old_set_time($temps)
{
round($temps);
$heures = floor($temps / 3600);
$minutes = round(floor(($temps - ($heures * 3600)) / 60));
if ($minutes < 10)
$minutes = "0" . round($minutes);
$secondes = round($temps - ($heures * 3600) - ($minutes * 60));
if ($secondes < 10)
$secondes = "0" . round($secondes);
return $minutes . ':' . $secondes;
}
function SetTime($sec, $padHours = true) {
if($sec < 3600)
return old_set_time($sec);
$hms = "";
// there are 3600 seconds in an hour, so if we
// divide total seconds by 3600 and throw away
// the remainder, we've got the number of hours
$hours = intval(intval($sec) / 3600);
// add to $hms, with a leading 0 if asked for
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';
// dividing the total seconds by 60 will give us
// the number of minutes, but we're interested in
// minutes past the hour: to get that, we need to
// divide by 60 again and keep the remainder
$minutes = intval(($sec / 60) % 60);
// then add to $hms (with a leading 0 if needed)
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
// seconds are simple - just divide the total
// seconds by 60 and keep the remainder
$seconds = intval($sec % 60);
// add to $hms, again with a leading 0 if needed
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}