数据库表: user 字段 数据类型 说明 id 自动编号 图片id img OLE 对象 保存图片
文章归档
ASP 获得图片宽度和高度的类
<% Class ImgWHInfo ‘获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP Dim ASO Private Sub Class_Initialize Set ASO=Server.CreateObject(“ADODB.Stream”) ASO.Mode=3 ASO.Type=1 ASO.Open End Sub Private Sub Class_Terminate Err.Clear Set ASO=Nothing End Sub Private Function Bin2Str(Bin) Dim I, Str For I=1 To LenB(Bin) clow=MidB(Bin,I,1) If ASCB(clow)<128 Then Str = Str & Chr(ASCB(clow)) Else I=I+1 If I <= LenB(Bin) Then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow)) End If Next Bin2Str = Str End Function Private Function Num2Str(Num,Base,Lens) Dim Ret Ret = “” While(Num>=Base) Ret = (Num Mod Base) & Ret Num = (Num – Num Mod Base)/Base Wend Num2Str = Right(String(Lens,”0″) & Num & Ret,Lens) End Function Private Function Str2Num(Str,Base) Dim Ret,I Ret = 0 For I=1 To Len(Str) Ret = Ret *base + Cint(Mid(Str,I,1)) Next Str2Num=Ret End Function Private Function BinVal(Bin) Dim Ret,I Ret = 0 For I = LenB(Bin) To 1 Step -1 Ret = Ret *256 + AscB(MidB(Bin,I,1)) Next BinVal=Ret End Function …
PHP 图片的二进制存取 (Mysql)
保存图片的字段 数据类型为:blob img.php <?php $filename = “Admin/Upload/3025994.jpg”; // 读取文件 $fp = fopen($filename,”rb”); $data = addslashes(fread($fp,filesize($filename))); fclose($fp); // 操作MYSQL $conn=mysql_connect(“localhost”,”root”,”admin”); @mysql_select_db(“mytest”,$conn); // 存入数据库 $query=”insert into pic values (5,’$data’)”; $result=mysql_query($query); $id=mysql_insert_id(); //读取数据 $query=”select * from pic where picid=5 limit 0,1″; $result=mysql_query($query); $row=mysql_fetch_array($result); $data = $row[“Pic”]; // 显示文件 header(“Content-type: image/*”); echo $data; ?> 在其他页面如下形式引用: <img src=”img.php”>
PHP 系统安装文件(install.php)
<?php if(isset($_POST[“Submit”])) { $mydbuser = $_POST[“m_root”]; $mydbpw = $_POST[“m_pw”]; $mydbname = $_POST[“m_db”]; $Admin_Name = $_POST[“Admin_Name”]; $Admin_Pwd = md5($_POST[“Admin_Pwd”]); if(!@mysql_connect(“localhost”,$mydbuser,$mydbpw)) { echo “<script>alert(‘mysql用户名或密码不正确!’)</script>”; } mysql_query(“set names ‘gbk'”); $dbsql = “CREATE DATABASE IF NOT EXISTS “.$mydbname; if(!@mysql_query($dbsql)) { echo “<script>alert(‘请检查是否有建数据库的权限!’)</script>”; } echo “<script>alert(‘数据库创建成功!’)</script>”; mysql_select_db($mydbname); $char = ”; if(mysql_get_server_info()> ‘4.1’) $char = ‘DEFAULT CHARSET=gbk’; $sql = “CREATE TABLE `Admin` ( `Admin_Id` int(255) unsigned NOT NULL auto_increment, `Admin_Name` varchar(20), `Admin_Pwd` mediumtext, PRIMARY KEY (`Admin_Id`) ) ENGINE=MyISAM {$char};”; if(!@mysql_query($sql)) { echo “<script>alert(‘请检查数据表 Admin 是否已存在,存在请先删除!’)</scri …
PHP循环语句
定义静态变量: static $name; 变量的变量: $a = “Hello”; $$a = “world”; //相当于 $Hello = “world”;
PHP常量类型
Apache 官方网站:http://www.apache.org PHP 官方网站:http://www.php.net 引用文件的方法: Require:用法:require(“MyRequireFile.php”); 通常放在 PHP 程序的最前面,PHP 程序在执行前,就先读入 require 所指定引入的文件,使它变成 PHP 程序网页的一部分。 Include:用法:include(“MyIncludeFile.php”); 一般放在流程控制处理部分中。PHP程序在读到include 的文件时,才将它读进来。这种方式,可以把程序执行时的流程简单化。
PHP 两个重要文件(config.php;function.php)
config.php <?php $mydbhost = ‘localhost’;//数据库服务器 $mydbuser = ‘root’;//数据库用户名 $mydbpw = ‘admin’;//数据库密码 $mydbname = ‘myclass’;//数据库名 $mydbcharset = ‘gbk’;//数据库编码,不建议修改. $Admin_Name = ‘admin’;//管理员名称 $Admin_Pwd = ‘21232f297a57a5a743894a0e4a801fc3′;//管理员密码 $eachpage = 5;//每页显示留言条数 //分页 $psql = “select count(*) from message”; $sum = “<b>”; $stail = “</b> ”; $link = “<a href=””; $lmid = “”>”; $ltail = “</a> ”; $curpage = “<a href=””; ?> function.php <?php class mysql{ function connect($dbhost, $dbuser, $dbpw, $dbname = ”,$dbcharset=”) { if(!@mysql_connect($dbhost, $dbuser, $dbpw)) { $this->show(‘Can not connect to MySQL server’); } if($dbname) { $this->select_db($dbname); } if($this->version() > …
PHP 生成验证码图片 checkcode.php
<?php // 设置图象的尺寸 $height = 17; $width = 47; $im = ImageCreateTrueColor($width, $height); $white = ImageColorAllocate ($im, 255, 255, 255); $blue = ImageColorAllocate ($im, 92, 146, 245); // draw on image ImageFill($im, 0, 0, $blue); //ImageLine($im, 0, 0, $width, $height, $white); $str=strtoupper(substr(md5(rand(0,100000)),0,5)); session_start(); $_SESSION[“yanzheng”]=$str; $yan=ImageString($im, 10, 3, 2, $_SESSION[‘yanzheng’], $white); for($i=0;$i<200;$i++) //加入干扰象素 { $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); } // 输出图象 Header (‘Content-type: image/png’); ImagePng ($im); // clean up ImageDestroy($im); ?>
PHP数值类型(array)
数组: 可以用array()语言结构来新建一个array。它接受一定数量用逗号分隔的key=>value参数对。 array([key=>] value,…) //key可以是integer或者string,value可以是任何值。 <?php $arr = array(“foo” => “bar”, 12 => true); echo $arr[“foo”]; // bar echo $arr[12]; // 1 ?>