dtpfia3334 2016-07-27 15:53
浏览 36
已采纳

将多个图像字段上载到服务器mysql中的每一行

In my post page i have multiple upload fields.

    <form action="" method="post" enctype="multipart/form-data"

    class="form-horizontal">

    <div class="form-group col-md-5">
    <label for="image">Big pic</label>
    <input id="image" type="file" name="image" class="btn btn-danger">
     </div>
     <div class="form-group col-md-5">
     <label for="img_v1">V1</label>
     <input id="img_v1" type="file" name="img_v1" class="btn btn-danger">
     </div>
     <div class="form-group col-md-5">
    <label for="img_v2">V2</label>
    <input id="img_v2" type="file" name="img_v2" class="btn btn-danger">
    </div>

And i want to upload each field to each row in my server.

my upload script is in the same file.

$error = ''; 
if(isset($_POST['submit_post'])){
$title = strip_tags($_POST['title']);
$date = date('Y-m-d h:i:s');
if($_FILES['image']['name'] !=''){
$image_name = $_FILES['image']['name']; 
$image_tmp = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_ext = pathinfo($image_name,PATHINFO_EXTENSION);
$image_path = '../clientes/img/'.$image_name;
$image_db_path = 'img/'.$image_name;
if($image_size < 10000000){
if($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'jpeg' ||       $image_ext == 'gif'){
if(move_uploaded_file($image_tmp,$image_path)){
$ins_sql = "INSERT INTO gallery (title, description, image, category,   status) VALUES ('$title', '$_POST[description]',
 '$image_db_path', '$_POST[category]', '$_POST[status]')";
  if(mysqli_query($conn,$ins_sql)){
  header('post_list.php');
 }else{
  $error = '<div class="alert alert-danger">Erro de script</div>';
  }
  }else{
  '<div class="alert alert-danger">Image cant upload</div>';
  } 
  }else{
  $error = '<div class="alert alert-danger">Wrong image extention</div>';
  }
  }else{
  $error = '<div class="alert alert-danger">Image is to much big</div>';
  }
  }else{
  $ins_sql = "INSERT INTO gallery (title, description, category, status,     date, author) VALUES ('$title', '$_POST[description]', 
  '$_POST[category]', '$_POST[status]', '$date', '$_SESSION[userName]    $_SESSION[userLName]')";
  if(mysqli_query($conn,$ins_sql)){
  header('post_list.php');
  }else{
  $error = '<div class="alert alert-danger">Script error</div>';
  }
  }
  }

i tried to upload the 3 fields to the server like this...

INSERT INTO gallery (title, description, image,img_v1, img_v2 category, status) VALUES ('$title', '$_POST[description]', '$image_db_path','$image_db_path','$image_db_path', '$_POST[category]', '$_POST[status]')";

But i know it was wrong. What i have to do so i can upload the extra img fields?

  • 写回答

1条回答 默认 最新

  • duanhan3067 2016-07-27 15:58
    关注

    You missed one comma between img_v2 and category.

    INSERT INTO gallery (title, description, image,img_v1, img_v2, category, status) VALUES ('$title', '$_POST[description]', '$image_db_path','$image_db_path','$image_db_path', '$_POST[category]', '$_POST[status]')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?