Creates a directory in the server’s file system.
function makeDirectory($path) {
if (!is_dir($path)) {
$oldumask = umask(0);
mkdir($path, 0777);
umask($oldumask);
chmod($path, 0777); // octal; correct value of mode
}
}
Month: March 2008
PHP Delete file
Delete a file in the file system. Note that this file system we’re talking about is the server’s file system. PHP nor other web-based programming language deletes a file system on the client’s side.
function deleteFile($filename) {
$do = unlink($filename);
if ($do=="1") {
echo "The file was deleted successfully.";
} else {
echo "There was an error trying to delete the file.";
}
}
PHP Get difference between 2 dates
This code gets the date difference manually, specifying a date value.
$digest_date = "2009-12-25";
$date_diff = abs(strtotime(date('y-m-d'))-strtotime($digest_date)) / 86400;
and another version in a method if you want to keep on reusing this code.
function dateDiff($dformat, $endDate, $beginDate) {
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}