Update of /cvsroot/upcase-project/UpCase/lib
In directory usw-pr-cvs1:/tmp/cvs-serv29238
Added Files:
uc_utils.php
Log Message:
some utility functions
--- NEW FILE: uc_utils.php ---
<?php
function checkVar($varname, $default = null)
{
if (!empty($_GET[$varname]))
return $_GET[$varname];
else if (!empty($_POST[$varname]))
return $_POST[$varname];
else
return $default;
}
function checkVarIn($varname, $ar, $default = null)
{
if (!empty($_GET[$varname]) && in_array($_GET[$varname], $ar))
return $_GET[$varname];
else if (!empty($_POST[$varname]) && in_array($_POST[$varname]))
return $_POST[$varname];
else
return $default;
}
function download($src, $dest, $blkSize = 1024)
{
$from_fd = fopen($src, "rb");
$to_fd = fopen($dest, "wb");
$buffer = '';
$byteCount = 0;
while ($buffer = fread($from_fd, $blkSize))
{
$res = fwrite($to_fd, $buffer, $blkSize);
$byteCount += $res;
flush();
if ($res < 0)
{
$byteCount = -1;
break;
}
if ($res < $blkSize)
break;
}
fclose($from_fd);
fclose($to_fd);
return $blkSize;
}
function createDirectory($path)
{
$ar = explode("/", $path);
$p = "";
foreach ($ar as $a)
{
if (!empty($a))
{
$p .= "/" . $a;
if (file_exists($p))
{
if (!is_dir($p))
return false;
}
else
mkdir($p, 0777);
}
}
return true;
}
?>
|