|
发表于 2012-7-20 16:31:22
|
显示全部楼层
生成静态页的cms 你现在不就是只差生成静态页
PHP复制代码
if (isset ( $_GET ['mkdir'] )) {
/***
* $uri_string= $this->uri->uri_string
* print_r($uri_string);
* 为嘛不用$uri_string,请打印如url是news和news/index时的情况
*/
$rsegments = $this->uri->rsegments;
$directory = '';
foreach ( $rsegments as $k => $v ) {
$directory .= '/' . $v;
}
$this->MakeDir ( $directory );
$dir_name = explode ( "/", $directory );
if ($dir_name ['1'] == $this->router->routes ['default_controller']) {
$directory = $this->router->method;
}
$directory .= $this->config->item ( 'url_suffix' );
$buffer = ob_get_contents ();
@ob_end_clean ();
if (! $fp = @fopen ( FCPATH . $directory, FOPEN_WRITE_CREATE_DESTRUCTIVE )) {
return FALSE;
}
flock ( $fp, LOCK_EX );
fwrite ( $fp, $buffer );
flock ( $fp, LOCK_UN );
fclose ( $fp );
}function MakeDir ($dir_name, $mode = 0777) {
$dir_name = str_replace ( "\\", "/", $dir_name );
$dir_name = preg_replace ( "#(/" . "/+)#", "/", $dir_name );
/**
* 干掉最后/
*/
$dir_name = preg_replace ( "~/[^/]+?$~i", "", $dir_name );
if (is_dir ( $dir_name ) !== false) {
return true;
}
$dir_name = explode ( "/", $dir_name );
$dirs = '';
foreach ( $dir_name as $key => $dir ) {
if (trim ( $dir ) != '') {
$dirs .= $dir . "/";
if (is_dir ( $dirs ) == false && @mkdir ( $dirs, $mode ) === false) {
return false;
}
}
}
return true;
}
复制代码
|
|