图片上传至数据库

获取提交的图片

$file_logo = $_FILES['img_logo'];

if($file_logo["error"] == 0){
 $file_type=array("image/jpeg","image/pjpeg","image/gif","image/png","image/x-png");
 打印图片的详细信息

// var_dump($file_logo['type']);
// exit;
 if(in_array($file_logo["type"],$file_type)){
 设置提交的图片最大尺寸 

 $MAX_SIZE=2000000;
  if($file_logo["size"] <= $MAX_SIZE){
   $new_name = time().mt_rand(10000,9999).strrchr($file_logo['name'],'.');
设置路径 

  $address = '../images/';
  $address1是为了在smarty模板中访问路径而设置

   $address1 = '/images/';

   移动至相应的文件夹下
   move_uploaded_file($file_logo["tmp_name"],$address.$new_name);
  收集数据

   $title = $_POST['title'];
   $shorttext = $_POST['shorttext'];
   $img_logo = $address1.$new_name;
   $content = $_POST['content'];
   添加至数据库 

   $q = "insert into news(title,news_logo,shorttext,content,time) values('$title','$img_logo','$shorttext','$content',now())";
    if(mysql_query($q) > 0){
    
       echo "添加成功.....<br /><br />";
       echo '.......<a href="news_desc.php">返回页面</a>';
     }
     else{
       echo "添加失败。。。";
     }
       }
  }
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值