PHP图片上传类带图片显示
2006-11-25 00:00
811 查看
这是一个PHP的文件上传类带图片显示的.其实做成函数就可以了.不过还是做成类好玩一点.~~~~
本来应该用JS来验证上传文件类型的.但懒得做了.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="upload" enctype="multipart/form-data" method="post" action="upload.php">
<input type="hidden" name="MAX_FILE_SIZE " />
<input type="file" name="file" />
<input type="submit" name="Submit" value="提交" />
</form>
</body>
</html>
<?php
Class upload
{
var $upload_name;
var $upload_tmp_address;
var $upload_server_name;
var $upload_filetype ;
var $file_type;
var $file_server_address;
var $image_w=900; //要显示图片的宽
var $image_h=350; //要显示图片的高
var $upload_file_size;
var $upload_must_size= 50000; //允许上传文件的大小,自己设置
function upload_file()
{
$this->upload_name = $_FILES["file"]["name"]; //取得上传文件名
$this->upload_filetype = $_FILES["file"]["type"];
$this->upload_server_name = date("Y_m_dH_i_s").$this->upload_name;
$this->upload_tmp_address = $_FILES["file"]["tmp_name"]; //取得临时地址
$this->file_type = array("image/gif","image/pjpeg"); //允许上传文件的类型
$this->upload_file_size = $_FILES["file"]["size"]; //上传文件的大小
if(in_array($this->upload_filetype,$this->file_type))
{ if($this->upload_file_size < $this->upload_must_size)
{
echo("上传成功,谢谢支持");
$this->file_server_address = "D:\usr\www\html\upload/".$this->upload_server_name;
move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//从TEMP目录移出
echo("<img src=$this->file_server_address width=$this->image_w height=$this->image_h/>"); //显示图片
}
else
{
echo("文件容量太大");
}
}
else
{
echo("不支持此文件类型,请重新选择");
}
}
}
$dd = new upload;
$dd->upload_file();
?>
本来应该用JS来验证上传文件类型的.但懒得做了.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="upload" enctype="multipart/form-data" method="post" action="upload.php">
<input type="hidden" name="MAX_FILE_SIZE " />
<input type="file" name="file" />
<input type="submit" name="Submit" value="提交" />
</form>
</body>
</html>
<?php
Class upload
{
var $upload_name;
var $upload_tmp_address;
var $upload_server_name;
var $upload_filetype ;
var $file_type;
var $file_server_address;
var $image_w=900; //要显示图片的宽
var $image_h=350; //要显示图片的高
var $upload_file_size;
var $upload_must_size= 50000; //允许上传文件的大小,自己设置
function upload_file()
{
$this->upload_name = $_FILES["file"]["name"]; //取得上传文件名
$this->upload_filetype = $_FILES["file"]["type"];
$this->upload_server_name = date("Y_m_dH_i_s").$this->upload_name;
$this->upload_tmp_address = $_FILES["file"]["tmp_name"]; //取得临时地址
$this->file_type = array("image/gif","image/pjpeg"); //允许上传文件的类型
$this->upload_file_size = $_FILES["file"]["size"]; //上传文件的大小
if(in_array($this->upload_filetype,$this->file_type))
{ if($this->upload_file_size < $this->upload_must_size)
{
echo("上传成功,谢谢支持");
$this->file_server_address = "D:\usr\www\html\upload/".$this->upload_server_name;
move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//从TEMP目录移出
echo("<img src=$this->file_server_address width=$this->image_w height=$this->image_h/>"); //显示图片
}
else
{
echo("文件容量太大");
}
}
else
{
echo("不支持此文件类型,请重新选择");
}
}
}
$dd = new upload;
$dd->upload_file();
?>
相关文章推荐
- 一款简单PHP图片上传类带图片显示代码
- PHP图片上传类带图片显示
- 解决php生成GD图片不显示问题
- php将图片以二进制保存到mysql数据库并显示
- php版阿里云OSS图片上传类详解
- PHP实现自动对图片进行滚动显示的方法
- php操作zip在不解压缩包的情况下显示压缩包中的图片
- PHP AJAXFORM提交图片上传并显示图片源代码
- 刷新一次变一次的图片代码-PHP随机显示图片代码:可制作头像或签名
- php网页显示正方形图片缩略图
- 如何解决php 生成验证码图片不显示问题
- PHP显示图片
- PHP后台技术-后台登录安全问题和显示多条图片数据库设计
- 用javascript+PHP随机显示图片
- php网页显示正方形图片缩略图
- php中随机显示图片的函数代码
- php上传图片到数据库与网页无法显示的问题