php学习3
夏峰:学会了用php进行文件打开,显示文件信息,和文件上传
<?php
$path='C:\AppServ\www\PHP2\wenjian.php';
// echo basename($path);
//basename显示文件名和扩展名
// echo "<br/>";
//echo dirname($path);
//返回目录部分
//print_r(pathinfo($path));
//获取文件的信息
$array_path=pathinfo($path);
echo $array_path[dirname];
?>
<?php
//这个叫做xiang对路径
//这个叫做jue对路径
//$path='wenjian2.php';
//echo realpath($path);
// ../是上翻
$path='../phpinfo.php';
echo realpath($path);
//echo $path;
?>
<?php
//确定指定文件大小
//round(X,2)保留两位小数
//$path='C:\AppServ\www\PHP2\wenjian.php';
//echo round(filesize($path)/1024,2).'KB';
//echo round(disk_free_space('C:')/1024/1024,2).'MB';
//disk_free_space()表示剩余可用空间的计算
//echo round(disk_total_space('C:')/1024/1024/1024,2).'GB';
//disk_total_space表示总空间
$path='C:\AppServ\www\PHP1\XF4.php';
//echo fileatime($path);
//此时显示的是一个时间戳,fileatime是获取最后的访问时间
//filectime是获取最后的改变时间,
//filemtime是最后的修改时间,文件内容修改的时间
date_default_timezone_set('Asia/Shanghai');
echo date('Y-m-d H:i:s',fileatime($path));
//date_default_timezone_set()将时区调整
//date()将时间戳格式化为时间
?>
<?php
//打开一个文件
//如果已经有啦这个文件,那么删除这个文件重新创建
//$fp = fopen('file.txt','w');
//$outstring='clearlove4396天下第一';
//fwrite($fp, $outstring,strlen($outstring));
//像fp代表的文件中写入数据
//关闭打开的文件
//fclose($fp);
//当只有一句话要输入,不需要做其他事的时候可以用
file_put_contents('file2.txt', 'clearlove8');
?>
盛宁:上传函数的学习和登录页面的制作,下次制作上传页面,但是选择数据库有点问题,得多思考一下:
<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
if(!$member_id=is_login($link)){
skip('login.php', 'error', '请登录之后再发帖!');
}
if(isset($_POST['submit'])){
include 'inc/check_publish.inc.php';
$_POST=escape($link,$_POST);
$query="insert into sfk_content(module_id,title,content,time,member_id) values({$_POST['module_id']},'{$_POST['title']}','{$_POST['content']}',now(),{$member_id})";
execute($link, $query);
if(mysqli_affected_rows($link)==1){
skip('publish.php', 'ok', '发布成功!');
}else{
skip('publish.php', 'error', '发布失败,请重试!');
}
}
$template['title']='帖子发布页';
$template['css']=array('style/public.css','style/publish.css');
?>
<?php include 'inc/header.inc.php'?>
<div id="position" class="auto">
<a href="index.php">首页</a> > 发布帖子
</div>
<div id="publish">
<form method="post">
<select name="module_id">
<option value='-1'>请选择一个子版块</option>
<?php
$where='';
if(isset($_GET['father_module_id']) && is_numeric($_GET['father_module_id'])){
$where="where id={$_GET['father_module_id']} ";
}
$query="select * from sfk_father_module {$where}order by sort desc";
$result_father=execute($link, $query);
while ($data_father=mysqli_fetch_assoc($result_father)){
echo "<optgroup label='{$data_father['module_name']}'>";
$query="select * from sfk_son_module where father_module_id={$data_father['id']} order by sort desc";
$result_son=execute($link, $query);
while ($data_son=mysqli_fetch_assoc($result_son)){
if(isset($_GET['son_module_id']) && $_GET['son_module_id']==$data_son['id']){
echo "<option selected='selected' value='{$data_son['id']}'>{$data_son['module_name']}</option>";
}else{
echo "<option value='{$data_son['id']}'>{$data_son['module_name']}</option>";
}
}
echo "</optgroup>";
}
?>
</select>
<input class="title" placeholder="请输入标题" name="title" type="text" />
<textarea name="content" class="content"></textarea>
<input class="publish" type="submit" name="submit" value="" />
<div style="clear:both;"></div>
</form>
</div>
<?php include 'inc/footer.inc.php'?>
自己项目的制作: