0

I can save an image with a text in a database mysql cepandant, I would like to record select several images at once by saving all these images in a colone of my table by separating them by visas. How can I do this please?

Any help will be appreciated!

It's my HTML code:

 <form action="saveimage.php" method="POST" enctype="multipart/form-data">


  <input type="text" name="name" placeholder="name image" required>  
  <input name="image[]" multiple required type="file"/>
  <button type="submit" value="Upload">Valider</button>
  </form>

It's my PHP code:

include("conn.php");
$name = $_POST['name'];
$image = addslashes(file_get_contents($_FILES['image'] 
['tmp_name']));
$query = "INSERT INTO images(name,image) values('$name','$image')";
$result = mysqli_query($conn,$query);
if ($result) {
echo 'success';
}else{
echo 'error';
}

What I want is that when the user clicks on 'send' the image colone fills with multiple images separated by commas.

2 Answers2

0

As far as I remember MySQL does not implement the ARRAY data type for columns.

The options I see are:

  1. Create a 1:N relationship between the main table, and an "images" table. Each row of the images table will hold one image using a BLOB data type.

  2. Use a single BLOB column in your table and somehow serialize all images into a single byte stream. This is, however, cumbersome.

I would go for option #1, since it's simpler to implement.

The Impaler
  • 45,731
  • 9
  • 39
  • 76
0

Usually you save images as blob in th database. It is not a varchar datatype, so that this in my opinion very difficult to realize that because you have to exclude that a comma byte is not in the image. You should change your design that it stores multiple images in their own row with a key that identifies it as belonging together. Of course Ou have to change also every access to that rable

nbk
  • 45,398
  • 8
  • 30
  • 47
  • Usually, you don't do this, and never if the image is more than ca. 100k. – Strawberry Jun 09 '19 at 17:06
  • would it be possible to select several images and save each in a conne apart from the table? If yes, how? –  Jun 09 '19 at 17:09
  • Look at this here is explained how you upload multiple files https://stackoverflow.com/questions/2704314/multiple-file-upload-in-php?answertab=active#tab-top and instead of uploading the fike store it into the database in the4 loop – nbk Jun 10 '19 at 21:44