导航:首页 > 编程语言 > phphtmltoimage

phphtmltoimage

发布时间:2022-11-29 23:22:23

㈠ 怎样用php实现上传图片到数据库

php实现上传图片保存到数据库的方法。具体分析如下:

php 上传图片,一般都使用move_uploaded_file方法保存在服务器上。但如果一个网站有多台服务器,就需要把图片发布到所有的服务器上才能正常使用(使用图片服务器的除外)
如果把图片数据保存到数据库中,多台服务器间可以实现文件共享,节省空间。

首先图片文件是二进制数据,所以需要把二进制数据保存在mysql数据库。
mysql数据库提供了BLOB类型用于存储大量数据,BLOB是一个二进制对象,能容纳不同大小的数据。

BLOB类型有以下四种,除存储的最大信息量不同外,其他都是一样的。可根据需要使用不同的类型。

TinyBlob 最大 255B
Blob 最大 65K
MediumBlob 最大 16M
LongBlob 最大 4G

数据表photo,用于保存图片数据,结构如下:

CREATETABLE`photo`(
`id`int(10)unsignedNOTNULLauto_increment,
`type`varchar(100)NOTNULL,
`binarydata`mediumblobNOTNULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=latin1AUTO_INCREMENT=1;

upload_image_todb.php代码如下:

<?php
//连接数据库
$conn=@mysql_connect("localhost","root","")ordie(mysql_error());
@mysql_select_db('demo',$conn)ordie(mysql_error());//判断action
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
//上传图片
if($action=='add'){
$image=mysql_escape_string(file_get_contents($_FILES['photo']['tmp_name']));
$type=$_FILES['photo']['type'];
$sqlstr="insertintophoto(type,binarydata)values('".$type."','".$image."')";
@mysql_query($sqlstr)ordie(mysql_error());
header('location:upload_image_todb.php');
exit();
//显示图片
}elseif($action=='show'){
$id=isset($_GET['id'])?intval($_GET['id']):0;
$sqlstr="select*fromphotowhereid=$id";
$query=mysql_query($sqlstr)ordie(mysql_error());
$thread=mysql_fetch_assoc($query);
if($thread){
header('content-type:'.$thread['type']);
echo$thread['binarydata'];
exit();
}
}else{
//显示图片列表及上传表单
?>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="content-type"content="text/html;charset=utf-8">
<title>uploadimagetodbdemo</title>
</head>

<body>
<formname="form1"method="post"action="upload_image_todb.php"enctype="multipart/form-data">
<p>图片:<inputtype="file"name="photo"></p>
<p><inputtype="hidden"name="action"value="add"><inputtype="submit"name="b1"value="提交"></p>
</form>

<?php
$sqlstr="select*fromphotoorderbyiddesc";
$query=mysql_query($sqlstr)ordie(mysql_error());
$result=array();
while($thread=mysql_fetch_assoc($query)){
$result[]=$thread;
}
foreach($resultas$val){
echo'<p><img
src="upload_image_todb.php?action=show&id='.$val['id'].'&t='.time().'"
width="150"></p>';
}
?>
</body>
</html>
<?php
}
?>

程序运行截图和数据库截图:

㈡ 用html或php怎样简单的实现单击下载图片

下面是来自ci的下载辅助函数,基本原理是生成一个能下载数据的http header,然后把文件数据发送过去就行啦。应该是可以直接用的,如果还有什么问题,我再看看啊
$data = file_get_contents("/path/to/photo.jpg"); // 读文件内容
$name = 'myphoto.jpg';

force_download($name, $data);

function force_download($filename = '', $data = '')
{
if ($filename == '' OR $data == '')
{
return FALSE;
}

// Try to determine if the filename includes a file extension.
// We need it in order to set the MIME type
if (FALSE === strpos($filename, '.'))
{
return FALSE;
}

// Grab the file extension
$x = explode('.', $filename);
$extension = end($x);

$mimes = array( 'bmp' => array('image/bmp','application/octet-stream'),
'gif' => array('image/gif','application/octet-stream'),
'jpeg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png' => array('image/png', 'image/x-png', 'application/octet-stream')
);

// Set a default mime if we can't find it
if ( ! isset($mimes[$extension]))
{
$mime = 'application/octet-stream';
}
else
{
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}

// Generate the server headers
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
header("Content-Length: ".strlen($data));
}
else
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
header("Content-Length: ".strlen($data));
}

exit($data);
}

㈢ php+html能够实现视频的在线 播放吗

1、通过网页(HTML5)调用摄像头,通过websocket传输给PHP后端(workerman), 再由后端广播给所有在线播放网页,观看者可以通过这个播放页面实时观看摄像头拍摄的内容。
2、
可以通过html版本的flash播放器
<p id="player3">
<a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
var s1 = new SWFObject("flvplayer.swf","single","300","170","7");
s1.addParam("allowfullscreen","true");
s1.addVariable("file","videos /ld.Flv");//这边是视频在本地的路径
s1.addVariable("image"," videos/ld.jpg");//这边是你的视频的截图
s1.addVariable("width","300");
s1.addVariable("height","170");
s1.write("player3");
</script>
通常是用flv 播放器。
3、你可以直接把视频的这段html代码弄过来。
<embed src="http://player.youku.com/player.php/sid/XNDc4NDU1NjAw/v.swf" allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>
,搞个层,点击时候,弹出这个视频。

㈣ php图片上传前预览怎么实现!!

1.先创建一个file表单域,我们需要用它来浏览本地文件。
<form name="form1" id="form1" method="post" action="upload.php">
<input type="file" name="file1" id="file1" />
</form>
2.试下效果:
判断文件类型:
当用户选择了一个图片文件时,希望他能马上看到这张图片的缩略图,以便他能确认没有把自己的光屁股照片当作头像传到服务器上^_^。
在预览之前还得先判断一下用户选择的是不是一个图像文件,如果他想用一个.rar文件做头像的话我们也需要礼貌地提醒一下。
<form name="form2" id="form2" method="post" action="upload.php">
<input type="file" name="file2" id="file2"
onchange="preview()" />
</form>
Javascript函数实现,注意使用DOM方法getElementById来访问对象。不要再使用form
和input的name属性来访问对象了,只有IE才这么干。<script type="text/javascript">
function preview2(){
var x = document.getElementById("file2");
if(!x || !x.value) return;
if(x.value.indexOf(".jpg")<0
&& x.value.indexOf(".jpeg")<0
&& x.value.indexOf(".gif")<0){
alert("您选择的似乎不是图像文件。");
}else{
alert("通过");
}
}
</script>
3.试下效果:

这里有一个问题,如果用户选择了名为“fake.jpg.txt”的文件,这段脚本仍旧会认为这是一个合法的图像文件。一个可行的解决方案是先 把文件名转换成小写,再取文件路径的最后4到5位,判断一下文件的扩展名是否确为支持的图像文件扩展名。不过这种方案略显笨拙,也没有什么美感可言, 我们换一种方案:用“正则表达式”来判断文件扩展名。
<script type="text/javascript">
function preview3(){
var x = document.getElementById("file3");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
alert("通过");
}else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
4.看看效果(可以自己创建一个“fake.jpg.txt”文件试试):

回到这段脚本上来,即使你还看不懂正则表达式那两行,但整段脚本的美感还是很明显的:简洁、直接、语义流畅,这与Web标准关于XHTML的要求是一致的,与Web设计师或开发者天生的“完美”主义也是一致的。
jjww一大段之后,转入重点——预览图片
预览功能的基本设计思路是很清晰的:创建一个img元素,再把文件域的value值赋值给img
元素的src属性。<form name="form4" id="form4" method="post" action="#">
<input type="file" name="file4" id="file4"
onchange="preview4()" />
<img id="pic4" src="http://blog.163.com/lgh_2002/blog/" alt="图片在此显示" width="120"/>
</form>
<script type="text/javascript">
function preview4(){
var x = document.getElementById("file4");
var y = document.getElementById("pic4");
if(!x || !x.value || !y) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
y.src = "file://localhost/" + x.value;
}else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
5.试下效果:

如果用的是Firefox(或Opera),可能会发现什么也没有发生。是的,很不幸Firefox的安全策略不允许显示一个用户的本地 图像文件。不知道为什么要这么做,个人觉得图像文件并不会造成严重的安全性问题。即使是不久前比较热门的那个会引起Windows崩溃的jpeg文 件,要显示它的前提条件是用户自己选择了这个文件或者你知道这个文件在用户硬盘上的准确路径。所以我想这种策略很可能来自于一个“懒惰”的开发人员,并 不想多写一些程序来区分这个本地文件是一个图像文件还是一个恶意文件,Firefox对安全性的要求让他们有些过于敏感了。
让Firefox显示本地文件的唯一办法就是修改它的默认安全策略:
在Firefox的地址栏中输入“about:config”
继续输入“security.checkloari”
双击下面列出来的一行文字,把它的值由true改为false
然后你可以再试试上面预览,everything works well!可惜的是并不能要求所有的用户都去修改这个值(更不用说修改的过程还挺麻烦),所以毫无意义。我们能做的也许就是接受Firefox不能预览本地图片这种“可笑”的局面。
用DOM来创建对象
在上面的XHTML代码中,为了预览图片,事先加入了一个没有设置src的img对象。除去不美观、代码冗余之外,如果用户浏览器不支持 Javascript,不仅无法使用这个功能,还要接受页面上一个永远不会显示出来的破图。要解决这个问题,就需要在“运行时”再生成这个img对 象,途径还是DOM。
<form name="form5" id="form5" method="post" action="#">
<input type="file" name="file5" id="file5"
onchange="preview5()"/>
</form>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("file5");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = 'file://localhost/' + x.value;
}else{
var img=document.createElement('img');
img.setAttribute('src','file://localhost/'+x.value);
img.setAttribute('width','120');
img.setAttribute('height','90');
img.setAttribute('id','img5');
document.getElementById('form5').appendChild(img);
}
}else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
6.试下效果:

这样就相对比较完美了。DOM和正则表达式一样,都是“包你不悔”的实 用技术,如果你希望更多了解、深入学习、或者顺利实践Web标准,DOM是不可或缺的。从本人最近的体会来说,Javascript+DOM+CSS蕴 藏着强大的能量,就看怎么释放它了。

7.最后帖上JQUERY的上传预览代码:

de><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://blog.163.com/lgh_2002/blog/jquery.js"></script>
<script language="javascript">
$(function(){
var ei = $("#large");
ei.hide();
$("#img1").mousemove(function(e){
ei.css({top:e.pageY,left:e.pageX}).html('<img style="border:1px solid gray;" src="http://blog.163.com/lgh_2002/blog/' + this.src + '" />').show();
}).mouseout( function(){
ei.hide("slow");
})
$("#f1").change(function(){
$("#img1").attr("src","file:///"+$("#f1").val());
})
});
</script>
<style type="text/css">
#large{position:absolute;display:none;z-index:999;}
</style>
</head>
<body>
<form name="form1" id="form1">
<div id="demo">
<input id="f1" name="f1" type="file" />
<img id="img1" width="60" height="60">
</div>
<div id="large"></div>
</form>
</body>
</html>de>

㈤ PHP图片生成

给你一个php 图像处理类,完全能实现你的功能,你自己研究一下吧

<?php
class image
{
var $w_pct = 50; //透明度
var $w_quality = 80; //质量
var $w_minwidth = 300; //最小宽
var $w_minheight = 300; //最小高
var $thumb_enable; //是否生成缩略图
var $watermark_enable; //是否生水印
var $interlace = 0; //图像是否为隔行扫描的
var $fontfile; //字体文件
var $w_img ; //默认水印图

function __construct()
{
global $SITE_CONFING;
$this->thumb_enable = $SITE_CONFING['thumb_enable'];
$this->watermark_enable = $SITE_CONFING['watermark_enable'];
$this->set($SITE_CONFING['watermark_minwidth'], $SITE_CONFING['watermark_minheight'], $SITE_CONFING['watermark_quality'], $SITE_CONFING['watermark_pct'], $SITE_CONFING['watermark_fontfile'],$SITE_CONFING['watermark_img']);
}

function image()
{
$this->__construct();
}

function set($w_minwidth = 300, $w_minheight = 300, $w_quality = 80, $w_pct = 100,$fontfile,$w_img)
{
$this->w_minwidth = $w_minwidth;
$this->w_minheight = $w_minheight;
$this->w_quality = $w_quality;
$this->w_pct = $w_pct;
$this->fontfile = $fontfile;
$this->w_img = $w_img;
}

function info($img)
{
$imageinfo = getimagesize($img); //返回图像信息数组 0=>宽的像素 1=>高的像素 2=>是图像类型的标记 3 =>是文本字符串,内容为“height="yyy" width="xxx"”,
if($imageinfo === false) return false;
$imagetype = strtolower(substr(image_type_to_extension($imageinfo[2]),1)); //获取图像文件类型 $imageinfo[2]是图像类型的标记
$imagesize = filesize($img); //图像大小
$info = array(
'width'=>$imageinfo[0],
'height'=>$imageinfo[1],
'type'=>$imagetype,
'size'=>$imagesize,
'mime'=>$imageinfo['mime']
);
return $info;
}

function thumb($image, $filename = '', $maxwidth = 200, $maxheight = 50, $suffix='_thumb', $autocut = 0)
{
if(!$this->thumb_enable || !$this->check($image)) return false;
$info = $this->info($image); //获取图片信息
if($info === false) return false;
$srcwidth = $info['width']; //源图宽
$srcheight = $info['height']; //源图高
$pathinfo = pathinfo($image);
$type = $pathinfo['extension']; //取得扩展名
if(!$type) $type = $info['type']; //如果没有取到,用$info['type']
$type = strtolower($type);
unset($info);
$scale = min($maxwidth/$srcwidth, $maxheight/$srcheight); //获取缩略比例
//获取按照源图的比列
$createwidth = $width = (int)($srcwidth*$scale); //取得缩略宽
$createheight = $height = (int)($srcheight*$scale); //取得缩略高
$psrc_x = $psrc_y = 0;
if($autocut) //按照缩略图的比例来获取
{
if($maxwidth/$maxheight<$srcwidth/$srcheight && $maxheight>=$height) //如果缩略图按比列比源图窄的话
{
$width = $maxheight/$height*$width; //宽按照相应比例做处理
$height = $maxheight; //高不变
}
elseif($maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width)//如果缩略图按比列比源图宽的话
{
$height = $maxwidth/$width*$height;
$width = $maxwidth;
}
$createwidth = $maxwidth;
$createheight = $maxheight;
}
$createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type); //找到不同的图像处理函数
$srcimg = $createfun($image); //新建图像
if($type != 'gif' && function_exists('imagecreatetruecolor'))
$thumbimg = imagecreatetruecolor($createwidth, $createheight); //新建一个真彩色图像
else
$thumbimg = imagecreate($width, $height); //新建一个基于调色板的图像

if(function_exists('imageresampled')) //重采样拷贝部分图像并调整大小,真彩
//imageresampled(新图,源图,新图左上角x距离,新图左上角y距离,源图左上角x距离,源图左上角y距离,新图宽,新图高,源图宽,源图高)
imageresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
else //拷贝部分图像并调整大小,调色板
imageresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight);
if($type=='gif' || $type=='png')
{
//imagecolorallocate 为一幅图像分配颜色
$background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 给基于调色板的图像填充背景色, 指派一个绿色
// imagecolortransparent 将某个颜色定义为透明色
imagecolortransparent($thumbimg, $background_color); // 设置为透明色,若注释掉该行则输出绿色的图
}
// imageinterlace 激活或禁止隔行扫描
if($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
$imagefun = 'image'.($type=='jpg' ? 'jpeg' : $type);
//imagejpeg imagegif imagepng
if(empty($filename)) $filename = substr($image, 0, strrpos($image, '.')).$suffix.'.'.$type; //获取文件名
//aaa.gif aaa_thumb.gif
$imagefun($thumbimg, $filename); //新建图像
imagedestroy($thumbimg); //销毁缩略图
imagedestroy($srcimg); //销毁源图
return $filename;
}
//watermark(源图,生成文件,生成位置,水印文件,水印文本,背景色)
function watermark($source, $target = '', $w_pos = 0, $w_img = '', $w_text = '', $w_font = 12, $w_color = '#cccccc')
{
if(!$this->watermark_enable || !$this->check($source)) return false;
if(!$target) $target = $source;
if ($w_img == '' && $w_text == '')
$w_img = $this->w_img;
$source_info = getimagesize($source);
$source_w = $source_info[0]; //获取宽
$source_h = $source_info[1]; //获取高
if($source_w < $this->w_minwidth || $source_h < $this->w_minheight) return false; //宽和高达不到要求直接返回
switch($source_info[2]) //新建图片
{
case 1 :
$source_img = imagecreatefromgif($source);
break;
case 2 :
$source_img = imagecreatefromjpeg($source);
break;
case 3 :
$source_img = imagecreatefrompng($source);
break;
default :
return false;
}
if(!empty($w_img) && file_exists($w_img)) //水印文件
{
$ifwaterimage = 1; //是否水印图
$water_info = getimagesize($w_img); //水印信息
$width = $water_info[0];
$height = $water_info[1];
switch($water_info[2])
{
case 1 :
$water_img = imagecreatefromgif($w_img);
break;
case 2 :
$water_img = imagecreatefromjpeg($w_img);
break;
case 3 :
$water_img = imagecreatefrompng($w_img);
break;
default :
return;
}
}
else
{
$ifwaterimage = 0;
//imagettfbbox 本函数计算并返回一个包围着 TrueType 文本范围的虚拟方框的像素大小。
//imagettfbbox ( 字体大小, 字体角度, 字体文件,文件 )
$temp = imagettfbbox(ceil($w_font*1.2), 0, $this->fontfile, $w_text);//取得使用 truetype 字体的文本的范围
$width = $temp[4] - $temp[6]; //右上角 X 位置 - 左上角 X 位置
$height = $temp[3] - $temp[5]; //右下角 Y 位置- 右上角 Y 位置
unset($temp);
}
switch($w_pos)
{
case 0: //随机位置
$wx = rand(0,($source_w - $width));
$wy = rand(0,($source_h - $height));
break;
case 1: //左上角
$wx = 5;
$wy = 5;
break;
case 2: //上面中间位置
$wx = ($source_w - $width) / 2;
$wy = 0;
break;
case 3: //右上角
$wx = $source_w - $width;
$wy = 0;
break;
case 4: //左面中间位置
$wx = 0;
$wy = ($source_h - $height) / 2;
break;
case 5: //中间位置
$wx = ($source_w - $width) / 2;
$wy = ($source_h - $height) / 2;
break;
case 6: //底部中间位置
$wx = ($source_w - $width) / 2;
$wy = $source_h - $height;
break;
case 7: //左下角
$wx = 0;
$wy = $source_h - $height;
break;
case 8: //右面中间位置
$wx = $source_w - $width;
$wy = ($source_h - $height) /2;
break;
case 9: //右下角
$wx = $source_w - $width;
$wy = $source_h - $height ;
break;
default: //随机
$wx = rand(0,($source_w - $width));
$wy = rand(0,($source_h - $height));
break;
}
if($ifwaterimage) //如果有水印图
{
//imagemerge 拷贝并合并图像的一部分
//参数(源图,水印图,拷贝到源图x位置,拷贝到源图y位置,从水印图x位置,从水印图y位置,高,宽,透明度)
imagemerge($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct);
}
else
{
if(!empty($w_color) && (strlen($w_color)==7))
{
$r = hexdec(substr($w_color,1,2)); //获取红色
$g = hexdec(substr($w_color,3,2)); //获取绿色
$b = hexdec(substr($w_color,5)); //获取蓝色
}
else
{
return;
}
//imagecolorallocate 基于调色板的图像填充背景色
//imagestring 水平地画一行字符串
//imagestring(源图,字体大小,位置X,位置Y,文字,颜色)
//参数($image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text)
imagettftext($source_img,$w_font,0,$wx,$wy,imagecolorallocate($source_img,$r,$g,$b),$this->fontfile,$w_text);
//imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$g,$b));
}
//输出到文件或者浏览器
switch($source_info[2])
{
case 1 :
imagegif($source_img, $target); //以 GIF 格式将图像输出到浏览器或文件
break;
case 2 :
imagejpeg($source_img, $target, $this->w_quality); //以 JPEG 格式将图像输出到浏览器或文件
break;
case 3 :
imagepng($source_img, $target); //以 PNG 格式将图像输出到浏览器或文件
break;
default :
return;
}
if(isset($water_info))
{
unset($water_info); //销毁
}
if(isset($water_img))
{
imagedestroy($water_img); //销毁
}
unset($source_info);
imagedestroy($source_img);
return true;
}
//gd库必须存在,后缀为jpg|jpeg|gif|png,文件存在,imagecreatefromjpeg或者imagecreatefromgif存在
function check($image)
{
return extension_loaded('gd') &&
preg_match("/\.(jpg|jpeg|gif|png)/i", $image, $m) &&
file_exists($image) &&
function_exists('imagecreatefrom'.($m[1] == 'jpg' ? 'jpeg' : $m[1]));
//imagecreatefromjpeg
//imagecreatefromgif
//imagecreatefrompng
}
}

/**
缩略图
1.新建一个图像资源 通过 imagecreatefromgif imagecreatefromjpeg imagecreatefrompng
2.imageresampled 拷贝图像,并调整大小

水印:图片水印,文字水印
1. 创建图像
2.加水印
图片水印:imagemerge 把2张图合并在一起
文字水印:imagettftext 向图像写入文字

*/
?>

㈥ PHP 图片处理

图片路径一定要基于当前php运行所在的路径去写,./图片 是当前目录,../图片 是上级目录,注意规范

㈦ PHP的值返回HTML显示

给你一段我以前用的,需要加载 jquery.min.js

login.php

<?php
header("Content-Type:text/html;charset=gb2312");

?>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<metaname="viewport"content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>

<title>xxxxx公司</title>
<style>
body{font:normal100%Helvetica,Arial,sans-serif;margin:0px;text-align:left;background:#FFF;height:100%;overflow:auto;}
table{border-collapse:collapse;}
a:link,a:visited,a:active,a:hover{color:#000;font-family:Arial,Helvetica,sans-serif;}
.linear{
FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#fff,endColorStr=#aaaaff);/*IE678*/
background:-ms-linear-gradient(top,#fff,#aaaaff);/*IE10*/
background:-moz-linear-gradient(top,#b8c4cb,#f6f6f8);/*火狐*/
background:-webkit-gradient(linear,0%0%,0%100%,from(#fff),to(#aaaaff));/*谷歌*/
background:-webkit-gradient(linear,0%0%,0%100%,from(#fff),to(#aaaaff));/*Safari4-5,Chrome1-9*/
background:-webkit-linear-gradient(top,#fff,#aaaaff);/*Safari5.1Chrome10+*/
background:-o-linear-gradient(top,#fff,#aaaaff);/*Opera11.10+*/
}
</style>
<scripttype="text/javascript"src="./js/jquery.min.js"></script>

<script>
varpsw_count=0
functionlogin_sys(){
if($.trim($("#gh_id").val())==""||$.trim($("#psd_id").val())==""){
$("#tips_message").html("工号和密码都不能空");
return;
}

varreg=/^(w|_)*$/;
varaaa=reg.test($.trim($("#gh_id").val()));
if(!aaa){
$("#tips_message").html("工号和密码的格式只能是英文数字");
return;

}
$("#tips_message").html("请稍侯....");
if(psw_count<4){
$.ajax({
type:"post",//使用post方法访问后台
dataType:"text",//返回text格式的数据
url:"ver_user.php",//要访问的后台地址
data:{find_gh:$.trim($("#gh_id").val()),cur_psw:$.trim($("#psd_id").val())},
async:false,
success:function(msg){//msg为返回的数据
if(msg>0){
$("#tips_message").html("用户名或密码错误("+psw_count+")");

}else{
$("#tips_message").html("用户名或密码正确");
window.location.href="index.php";
}
}
});
psw_count=psw_count+1
}else{
$("#tips_message").html("错误超过3次,请查对");
$("#login_btn").hide();
}

}
functionlogin_sys_admin(){

window.location.href="admin_login.php";

}
</script>
</head>
<body>

<tablealign="center"border="1"cellpadding="0"cellspacing="1"bordercolor="#d1d1d1">
<tr><thcolspan="2"align="center"class="linear"style="font-family:华文中宋;color:red;font-size:1.8em"></br>利生厂员工查询系统欢迎您</br></br></th></tr>
<tr><tdcolspan="2">&nbsp</td></tr>

<trfont-size="12"><td>今天是:</td><td><?=gmdate("Y年n月j日",time()+8*3600)?></td></tr>
<tr><tdcolspan="2">&nbsp</td></tr>
<tr><td>工号:</td><td><inputtype="text"class="input_text"id="gh_id"name="gh"size="16"title="不能为空且不能有空格,只能英文数字"value=""/></td></tr>
<tr><td>密码:</td><td><inputtype="password"class="input_text"id="psd_id"name="acc-code"size="8"title="不能为空且不能有空格,只能英文数字"value=""/>(4-6位英数)</td></tr>

<tr><td>验证码</td><td>&nbsp</td></tr>

<tr><tdcolspan="2"align="center"><spanid="tips_message"style="font-family:华文中宋;color:red;">&nbsp</span></td></tr>
<tr><tdcolspan="2"align="center"><inputid="login_btn"type="button"onclick="login_sys()"style="width:100px"value="登录"/></td></tr>
<tr><tdcolspan="2"align="center">----------</td></tr>
<tr><tdcolspan="2"align="center">
<inputid="login_btn"type="button"onclick="login_sys_admin()"style="width:100px"value="系统操作员登录"/>

</td></tr>

</table>

</body>
</html>

ver_user.php

<?
session_start();

header("Content-Type:text/html;charset=gb2312");
$myconn=odbc_connect("VFP_SYS_FTB","","");

$strSql="select`gh`,`yg_name`,`acc_code`,`fenchang`,`work_type`from`.lishenggh`wherelz=.f.andgh='$find_gh'";

$result=odbc_do($myconn,$strSql);
$gh="";
$yg_name="";
$acc_code="";
$fenchang="";

while(odbc_fetch_row($result))//通过循环读取数据内容
{
$gh=odbc_result($result,1);
$yg_name=odbc_result($result,2);
$acc_code=odbc_result($result,3);
$fenchang=odbc_result($result,4);
$work_type=odbc_result($result,5);

}
odbc_close($myconn);
if($gh){
if(trim($cur_psw)==trim($acc_code)){
$_SESSION['gh']=$gh;
$_SESSION['yg_name']=$yg_name;
$_SESSION['acc_code']=$acc_code;
$_SESSION['fenchang']=$fenchang;
$_SESSION['work_type']=$work_type;
switch($_SESSION['fenchang']){
case0:
$_SESSION['fch_name']="生产";
break;
case1:
$_SESSION['fch_name']="后勤";

break;
case2:
$_SESSION['fch_name']="行政";

break;
}
echo"0";
}else{
echo"1";

}

}else{
echo"2";

}

?>

㈧ php上传图片的问题!

首先在php的目录下,建一个images的文件夹

把以代码另存为upload.php
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>PHP Code
<?php
//define a maxim size for the uploaded images
define ("MAX_SIZE","10000000");
// define the width and height for the thumbnail
// note that theese dimmensions are considered the maximum dimmension and are not fixed,
// because we have to keep the image ratio intact or it will be deformed
define ("WIDTH","170");
define ("HEIGHT","120");

// this is the function that will create the thumbnail image from the uploaded image
// the resize will be done considering the width and height defined, but without deforming the image
function make_thumb($img_name,$filename,$new_w,$new_h)
{
//get image extension.
$ext=getExtension($img_name);
//creates the new image using the appropriate function from gd library
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);

if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);

//gets the dimmensions of the image
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);

// next we will calculate the new dimmensions for the thumbnail image
// the next steps will be taken:
// 1. calculate the ratio by dividing the old dimmensions with the new ones
// 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
// and the height will be calculated so the image ratio will not change
// 3. otherwise we will use the height ratio for the image
// as a result, only one of the dimmensions will be from the fixed ones
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

// we create a new image with the new dimmensions
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

// resize the big image to the new created one
imageresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

// output the created image to the file. Now we will have the thumbnail into the file named by $filename
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);

//destroys source and destination images.
imagedestroy($dst_img);
imagedestroy($src_img);
}

// This function reads the extension of the file.
// It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

// This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.
$errors=0;
// checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
// if it is not empty
if ($image)
{
// get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);

// get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
// if it is not a known extension, we will suppose it is an error, print an error message
//and will not upload the file, otherwise we continue
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
// get the size of the image in bytes
// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
$copied = ($_FILES['image']['tmp_name'], $newname);
//we verify if the image has been uploaded, and print error instead
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
// the new thumbnail image will be placed in images/thumbs/ folder
$thumb_name='images/'.$image_name;
// call the function that will create the thumbnail. The function will get as parameters
//the image name, the thumbnail name and the width and height desired for the thumbnail
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
//If no errors registred, print the success message and show the thumbnail image created
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Thumbnail created Successfully!</h1>";
echo '<img src="'.$thumb_name.'">';
}
?>

阅读全文

与phphtmltoimage相关的资料

热点内容
小苮儿网盘提取码 浏览:238
怎么给磁盘加密c盘 浏览:381
内核驱动编译v1 浏览:575
韩国电影伦理中文 浏览:67
大乐透复式算法计算器 浏览:845
啄木鸟40部 浏览:502
我的世界服务器版本下载地址 浏览:925
怎么制作一个游戏的服务器 浏览:800
python中xticks用法 浏览:905
西瓜视频解压软心砖 浏览:137
程序员被孤立怎么办 浏览:807
主角秦风重生小说免费全文阅读 浏览:937
电影名卧布吉岛 浏览:161
泰国肉肉电影 浏览:499
电影无处可逃结局是什么 浏览:102
压缩性模量 浏览:352
平安老师讲解压力化解 浏览:459
快递员的电影是什么名字 浏览:780
日本电影叫什么鱼的名字 浏览:663
找书pdf 浏览:392