Reputation: 19
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 ?
Upvotes: 1
Views: 3553
Reputation: 1788
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);
Upvotes: 0
Reputation: 9928
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.
Upvotes: 1
Reputation: 8697
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
Upvotes: 0
Reputation: 2464
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 />
Upvotes: 0