Multiple file upload in php

前端 未结 14 1628
轮回少年
轮回少年 2020-11-21 11:32

I want to upload multiple files and store them in a folder and get the path and store it in the database... Any good example you looked for doing multiple file upload...

14条回答
  •  余生分开走
    2020-11-21 12:09

    HTML

    1. create div with id='dvFile';

    2. create a button;

    3. onclick of that button calling function add_more()

    JavaScript

    function  add_more() {
      var txt = "
    "; document.getElementById("dvFile").innerHTML += txt; }

    PHP

    if(count($_FILES["item_file"]['name'])>0)
     { 
    //check if any file uploaded
     $GLOBALS['msg'] = ""; //initiate the global message
      for($j=0; $j < count($_FILES["item_file"]['name']); $j++)
     { //loop the uploaded file array
       $filen = $_FILES["item_file"]['name']["$j"]; //file name
       $path = 'uploads/'.$filen; //generate the destination path
       if(move_uploaded_file($_FILES["item_file"]['tmp_name']["$j"],$path)) 
    {
       //upload the file
        $GLOBALS['msg'] .= "File# ".($j+1)." ($filen) uploaded successfully
    "; //Success message } } } else { $GLOBALS['msg'] = "No files found to upload"; //No file upload message }

    In this way you can add file/images, as many as required, and handle them through php script.

提交回复
热议问题