1
for($i=1; $i<=count($_FILES); $i++)
    {
     $attachment1 = $_FILES['client_attachment']['name']; 
    }
    $arr = implode(',', $attachment1); 

$query = "INSERT INTO tbl_docs(id, post_id, client_docs) VALUES('','".$_POST['post_ID']."', '".implode(',', $attachment1)."')");

how to add multiple image in single column ?

Max
  • 19
  • 1
  • 3

4 Answers4

1

Joomla! uses json format to store few images in a single column/field on database for an article. You may go with the same way. The following code is not Joomla!'s.

$imageArray = array();

for($i=1; $i<=count($_FILES); $i++)
{
    $imageArray[$i] = $_FILES['client_attachment']['name']; 
}

$arr = json_encode($imageArray); 

When you want to call the attached image names you may use

$imagesGetBack= json_decode($arr, true); 

true is for associative array, false is for indexed array.

zkanoca
  • 9,664
  • 9
  • 50
  • 94
0

Unfortunately, your Question isn't that clear. Here's an idea:

I think, it's not possible that way. PHP just gets the sent file-inputs. You could combine them with an array, like:

File 1: <input type="file" name="images[]"/>
File 2: <input type="file" name="images[]"/>

Or one field for multiple files:

Files: <input type="file" name="images[]" multiple/>

You should use Javascript for developing a HTML5 Multi Upload, if necessary. With JS you're able to edit the DOM and add hidden file-inputs.

There are a lot of good scripts out there. Check out: Plupload

Mr. B.
  • 8,041
  • 14
  • 67
  • 117
  • I dont think OP is asking how to upload multiple images, but rather how to store multiple images(name) in database. – Roy M J Sep 18 '13 at 11:51
  • @RoyMJ Yes, you could be right. His question isn't that clear, unfortunately. – Mr. B. Sep 18 '13 at 11:53
  • for($i=0; $i<=count($footer_options); $i++) { $footer[] = $footer_options; }implode(',', $footer[0]) – Max Sep 18 '13 at 12:01
  • i stored multiple text in single field in database table – Max Sep 18 '13 at 12:09
0

You'll want to make them into an array:

$attachment = array();

for($i=0; $i<=count($_FILES); $i++)
    {
     $attachment[$i] = $_FILES['client_attachment']['name']; 
    }
    $arr = implode(',', $attachment); 
Gary Hayes
  • 1,728
  • 1
  • 15
  • 23
  • And it gives error : Warning: implode(): Invalid arguments passed – Max Sep 18 '13 at 12:26
  • I was just showing you how to make the array, not pass the info with $_POST or $_GET. You'll have to figure that out yourself, as there are many ways you can do it, you'll have to decide which is best for you. I also don't know what you're using implode for, so I left it in there because I was just fixing your coding. Passing the files should be very similar to the 'select multiple' method when processing the array on server side. – Gary Hayes Sep 18 '13 at 21:36
0

You have two choices. You can allow the user to upload a .zip or .tar file, or you can use a multiple upload input. Using the multiple upload input will rely on their browser offering HTML. Don't forget the square brackets in the name of your input field if you're using multiple:

<input name="client_attachment[]" type="file" id="client_attachment" multiple />
Boundless
  • 2,444
  • 2
  • 25
  • 40