PHP从页面上传图片到数据库(实例)
来源:互联网 发布:大数据产业市场规模 编辑:程序博客网 时间:2024/05/22 04:35
PHP页面
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
// include 'templates/init.php'; //什么东西
//初始化act
$_REQUEST['act']=$_REQUEST['act']?$_REQUEST['act']:'';
if($_REQUEST['act']=='add'){
include 'templates/tupian_add.php';
}elseif($_REQUEST['act']=='insert'){ //文件上传
$brand=$_FILES['logo'];
if($brand['error']==0){
//判断用户提交的图片格式是否是我要求的格式
$allow_type=array('image/gif','image/jpeg','image/png','image/pjpeg');
if(in_array($brand['type'],$allow_type)){
//符合要求
//在判断提交的大小
$max_size=20000000;
if($brand['size']<=$max_size){
//容许上传到服务器
$new_file_name=time().mt_rand(10000,99999).strrchr($brand['name'],'.');//新文件夹
move_uploaded_file($brand['tmp_name'],'file_photos/'.$new_file_name);
//var_dump($new_file_name);
$brand_logo='file_photos/'.$new_file_name;
//var_dump($title,$content,$time);
include 'db.class.php';
$db=new db('localhost','root','123','fanyi');
$sql="insert into tupian values(null,'$brand_logo')";
if(mysql_query($sql)){
echo "图片添加成功";
//header("Refresh: 2; url=http://localhost/admin/brand.php?act=list");
}
}
}
}
}
-----------------------------------------------------------------------------------------------------------------
HTML页面
<form method="post" action="tupian.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
<tr>
<td class="label"><a href="javascript:showNotice('warn_brandlogo');" title="点击此处查看提示信息">
<img src="images/notice.gif" width="16" height="16" border="0" alt="点击此处查看提示信息"></a>图片LOGO</td>
<td><input type="file" name="logo" id="logo" size="45"> <br /><span class="notice-span" style="display:block" id="warn_brandlogo">
请上传图片 </span>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br />
<input type="submit" class="button" value=" 确定 " />
<input type="reset" class="button" value=" 重置 " />
</td>
</tr>
</table>
</form>
- PHP从页面上传图片到数据库(实例)
- Smarty从数据库中提取图片显示到页面(实例)
- 如何从数据库调出数据显示到页面PHP+Mysql+Html(简单实例)
- 如何从数据库调出数据显示到页面 PHP+Mysql+Html(简单实例)
- 从数据库调出数据显示到页面 PHP+Mysql+Html(简单实例)
- 用Seam实现:图片上传 + 保存到数据库 + 从数据库读出图片并显示到页面中
- 用Seam实现:图片上传 + 保存到数据库 + 从数据库读出图片并显示到页面中
- 从页面插入信息到数据库(简单实例)
- 如何从页面向数据库插入信息(PHP实例)
- php 上传图片保存到数据库例子
- php 上传图片保存到数据库例子
- php 上传图片保存到数据库例子
- php实现上传图片到数据库
- javaweb上传图片,并且从数据库中查出,在页面显示,同时保存图片到数据库中
- vue上传图片到数据库并显示到页面
- (一)上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)
- (二)上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)
- 上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)(1)
- main函数中的argc与argv
- 程序崩溃时自动记录minidump的c++类
- “Runtime Error”不产生dump文件的解决办法
- Hadoop源码之Map/Reduce应用过程
- 字符设备驱动开发流程(总结)
- PHP从页面上传图片到数据库(实例)
- ADB WINDOWS下显示乱码
- 【shell】shell脚本的调试方式(二)
- Android 调试方法
- 使用Windbg生成dump文件
- STM32第二功能引脚映射
- OGNL表达式struts2标签“%,#,$”
- Andriod Sensor
- Ubuntu下Firefox安装flashplayer