-4

I am new to php. I want to know how to change single image upload php to multi image upload.

Below is my code:-

<?php
require_once("header.php");
require_once("nav.php");   

// Count total files
  $countfiles = count($_FILES['files']['name']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frm_add_channel")) {
if(isset($_FILES['image']['tmp_name']))
{
  $file = $_FILES['image']['tmp_name'];
  $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
  $image_name = addslashes($_FILES['image']['name']);

  move_uploaded_file($_FILES['image']['tmp_name'],"images/album" . $_FILES['image']['name']);

  $albumid = $_POST['albumid'];
  $name = str_replace("'","''",$name);
  $place = $_POST['place'];
  $place = str_replace("'","''",$place);
  $owner = $_POST['owner'];
  $type = $_POST['type'];
  $path = $_FILES['image']['name'];

  $sql = "INSERT INTO images (name,image,sys_album_id)
  VALUES ('$path','$name','$albumid')";
  $result = mysql_query($sql);

  //$int_id = mysql_num_rows($result);
  $int_id = mysql_num_rows();



  echo '<script type="text/javascript">alert("Successfully Add New Channel!");location.href="gallery_upload.php";</script>';
    }
  }
?>




<br><br><br><br><br><br><br>

<?php echo $_GET['id'];?>
        <form name="frm_add_channel" method="post" action='' enctype='multipart/form-data'>
          <h4>Image (Less Than 2MB)</h4>
          <img src="upload/qm.jpg" id="imgAvatar" alt="Course Image" />
          <p><input type="file" name="image" id="image" onChange="showPreview(this)" accept="image/*" multiple /></p><br>



<input type="text" class="form" name="albumid" value"<?php echo $_GET['id'];?>" size="30" />
          <p><input type="submit" value="Add Album" onclick="return checking()" /></p><br>
          <input type="hidden" name="MM_insert" value="frm_add_channel">
        </form>
2

1 Answer 1

1

try this below changed html & PHP file

   $countfiles = count($_FILES['image']['name']);


   for($i=0;$i<$countfiles;$i++)
   {

      $file = $_FILES['image']['tmp_name'][$i];
      $image = addslashes(file_get_contents($_FILES['image']['tmp_name'][$i]));
      $image_name = addslashes($_FILES['image']['name'][$i]);

      move_uploaded_file($_FILES['image']['tmp_name'][$i],"images/album" . $_FILES['image']['name'][$i]);
       ......
       ....
   }



 <form name="frm_add_channel" method="post" action='' enctype='multipart/form-data'>
                  <h4>Image (Less Than 2MB)</h4>
                  <img src="upload/qm.jpg" id="imgAvatar" alt="Course Image" />
                  <p><input type="file" name="image[]" id="image" onChange="showPreview(this)" multiple /></p><br>



        <input type="text" class="form" name="albumid" value"<?php echo $_GET['id'];?>" size="30" />
                  <p><input type="submit" value="Add Album" onclick="return checking()" /></p><br>
                  <input type="hidden" name="MM_insert" value="frm_add_channel">
                </form>
Sign up to request clarification or add additional context in comments.

1 Comment

I am still getting one image uploaded

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.