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 ?

4

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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 />

Comments

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

4 Comments

I dont think OP is asking how to upload multiple images, but rather how to store multiple images(name) in database.
@RoyMJ Yes, you could be right. His question isn't that clear, unfortunately.
for($i=0; $i<=count($footer_options); $i++) { $footer[] = $footer_options; }implode(',', $footer[0])
i stored multiple text in single field in database table
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); 

2 Comments

<input type='file' name='client_attachement[]'><input type='file' name='client_attachement[]'><input type='file' name='client_attachement[]'> And it gives error : Warning: implode(): Invalid arguments passed
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.

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.