如何使用php上传md5名称的多个图像?

时间:2018-04-24 04:49:07

标签: php md5

<?php
include"db.php";
if(isset($_POST['btn_upload']))
{
 $v1=rand(1111,9999);
 $v2=rand(1111,9999);
 $v3=$v1.$v2;
 $v3=md5($v3);

for($i=0; $i<count($_FILES["file_img"]["name"]); $i++ )
 {
  //select folder id to insert all images
   $folder_name=$_POST['select_folder_name'];


    $filename=$_FILES["file_img"]["name"][$i];
    $filetype=$_FILES["file_img"]["type"][$i];
    $gallery_image_dst="./gallery_image/".$v3.$filename;
    $gallery_image_location="gallery_image/".$v3.$filename;
    move_uploaded_file($_FILES["file_img"]["tmp_name"],$gallery_image_dst);

  //insert image name, path, type and folder name to database.
  $insert_gallery= "INSERT INTO `gallery`(`image_name`, `image_path`, 
  `image_type`,`folder_name`) VALUES 
  ('$filename','$gallery_image_location','$filetype','$folder_name')";

   $result=mysqli_query($conn, $insert_gallery);         
   if($result){
        echo"<script>alert('Successfully uploaded')</script>";
        echo"<script>window.open('index.php?upload_images','_self') 
        </script>";
   }else{
       echo"<script>alert('Oop! Somthing going wrong')</script>";
   }  
  } 
 }
?>

这里我将获取数据库中的所有图像位置,图像类型和图像md5名称。但问题是我没有得到任何图像到我的gallery_image文件夹。成功上传消息后我收到错误警告:move_upload_file()期望参数1为字符串,数组以c“\ xampp ........位置和行号

给出

2 个答案:

答案 0 :(得分:2)

你错过了索引[$ i]

你必须更新,

 move_uploaded_file($_FILES["file_img"]["tmp_name"][$i],$gallery_image_dst);

答案 1 :(得分:0)

enter image description here

添加move_uploaded_file($ _ FILES [“file_img”] [“tmp_name”] [$ i],$ gallery_image_dst); 我无法打开流错误。请找到附带的屏幕截图。