Location: PHPKode > projects > Todo Manager > todo/library/file.lib.php
<?php
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/library/util.lib.php";

/**
 * example:
 *		file_concat("dir1/", "dir2", "*") // returns "dir1/dir2/*"
 */
function file_concat() {
	$result = NULL;
	$dirs = func_get_args();
	foreach ($dirs as $dir) {
		if (util_empty($dir))
			continue;
		if (!util_empty($result))
			$result .= "/";
		$result .= $dir;
	}
	$result = preg_replace("#/+#", "/", $result);
	return $result;
}

function file_copy($source, $destination, &$error) {
	if (!file_exists($source)) {
		$error = "File or folder not found";
		return FALSE;
	}
	
	if (filetype($source) == "dir") {
		$dirname = basename($source);
		$destination = file_concat($destination, $dirname);
		if (!file_exists($destination))
			mkdir($destination);
		$files = glob(file_concat($source, "*"));
		foreach($files as $file) {
			if (!file_copy($file, $destination, $error))
				return FALSE;
		}
	} else {
		$filename = $destination;
		if (file_exists($filename) && (filetype($filename) == "dir"))
			$filename = file_concat($filename, basename($source));
		
		if (file_exists($filename)) {
			$error = "File already exists in the destination folder";
			return FALSE;
		}
		
		copy($source, $filename);
	}
	
	return TRUE;
}

function file_unlink($source, &$error) {
	if (!file_exists($source)) {
		$error = "File or folder not found";
		return FALSE;
	}
	
	if (filetype($source) == "dir") {
		$dirname = basename($source);
		$files = glob(file_concat($source, "*"));
		foreach($files as $file) {
			if (!file_unlink($file, $error))
				return FALSE;
		}
		rmdir($source);
	} else {
		unlink($source);
	}
	
	return TRUE;
}

function file_move($source, $destination, &$error) {
	return file_copy($source, $destination, $error) && file_unlink($source, $error);
}

function file_unix_filename($filename) {
	return str_replace(" ", "_", strtolower($filename));
}

function file_mime_type($file) {
	$result = NULL;
	
    if (function_exists("mime_content_type")) {
        $result = mime_content_type($file);
    } else
	if (!util_empty( $mime = @shell_exec("file -bi " . escapeshellarg($file)) )) {
        $result = trim($mime);
    } else {
        if (extension_loaded("fileinfo.so") || dl("fileinfo.so")) {
            if (function_exists("finfo_open")) {
                $f = finfo_open(FILEINFO_MIME);
                $mime = finfo_file($f, $file);
                finfo_close($f);
                return $mime;
            } elseif (class_exists('finfo')) {
                $f = new finfo(FILEINFO_MIME);
                return $info->file($file);
            }
        }
    }
	
	return $result;
}
?>
Return current item: Todo Manager