使用foreach循环上传多张图片并插入数据库 [英] multiple image upload using foreach loop and inserting to database

查看:188
本文介绍了使用foreach循环上传多张图片并插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取想要将其插入数据库中的图像文件时遇到麻烦,我想要 像我这样上传的照片:

I am having trouble getting the image files I wanted them to insert in my database I want the picture like the one I uploaded like this:

insert into('pic1.jpg');

insert into('pic2.jpg');

insert into('pic3.jpg');

不是这样的:

insert into(Array[0] => pic1.jpg, Array[1] => pic2.jpg, Array[2] => pic3.jpg);

所以我只能得到他们的名字,然后插入我的数据库中 我需要使用 foreach循环

so i can get their name only and insert in in my database im required to use foreach loop

  if(isset($_POST['upload'])){
      $upload[] = ($_FILES['images']['name']);
      print_r($upload);
   }


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <form method="POST" enctype="multipart/form-data">        
        <input type="file" name="images[]" multiple="multiple">
        <input type="submit" name="upload" value="upload">
        </form>
    </body>
</html>

推荐答案

尝试一下...

   foreach ($_FILES['image']['tmp_name'] as $key => $val ) {

        $filename = $_FILES['image']['name'][$key];
        $filesize = $_FILES['image']['size'][$key];
        $filetempname = $_FILES['image']['tmp_name'][$key];

        $fileext = pathinfo($fileName, PATHINFO_EXTENSION);
        $fileext = strtolower($fileext);

        // here your insert query
    }

这篇关于使用foreach循环上传多张图片并插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆