A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 众生 初级黑马   /  2019-5-31 13:03  /  698 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

文件上传
客户端
   <form action=""  method="post"  enctype="multipart/form-data" > .....</form>
    <input  type="file"  name="myfile1"   />
   <input  type="file"  name="myfile2[]"  multiple   />
服务器端
    move_uploaded_file(源文件, 目标文件)
   move_uploaded_file($_FILES['myflie1']['tmp_name'],  './upload/xxx.png')
附加其他
    判断是否有文件上传:if( !empty($_FILES) {.... }
    限定类型:
          <Input type="file" name="xxx"  accept=".jpg, .png, gif" />
          $type=$_FILES['type']   //获得类型
          if(strpos( $type, "image/") === 0 ){ .... }
     给出合理的文件名
          后缀:$ext = strrchr( $_FILES['myfile']['name'],  '.');
          文件名: $fileName = time() . rand(10000, 99999) . $ext  
     限制上传大小:
           php.ini中:upload_max_filesize
           php.ini中: post_max_size
罗列几个函数:explode(),  implode(),  strpos(),  strrchr()
http协议应用:
       设定返回的文档内容类型:
                  header("content-type:text/html; charset=utf-8");
                 header("content-type:text/css; charset=utf-8");
                 header("content-type:text/javasript");
                 header("content-type:text/json");
                 header("content-type:image/png");
         立即跳转:header("location:一个url地址");
         定时跳转:header("refresh:秒数; url=一个url地址");
         设定链接为一个下载操作:header("Content-Type: application/octet-stream");
   
// 假定数据库用户名:root,密码:123456,数据库:baixiu
$connection = mysqli_connect("localhost", "root", "123456", "baixiu");
执行查询语句
使用形式:
$result = mysqli_query($link,$sql);
解析结果集的多种方式

l  mysql_fetch_row():返回索引数组

l  mysql_fetch_assoc():返回关联数组。

l  mysql_fetch_array():返回混合数组。

1)        mysqli_fetch_array(resource $res);

?        返回结果集中的一行,以混合数组形式返回。既有数字下标,又有字符下标(查询各个字段名称)。

?        使用查询字段的名称作为字符下标。

?        函数的参数必须为查询结果集

?        每次执行移动一次指针,返回一行数据。

2)        mysqli_fetch_row($res);

?        返回为索引数组。

3)        mysqli_fetch_assoc($res);

返回关联数组,元素下标为查询字段的名称。
常见查询函数

- 总条数 —— count 分页功能,查询总页数
- 最大值、最小值 —— max/min
- 平均值 —— avg

//获取表单所有带name属性的元素

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马