Jump to content

Adamm99

New Members
  • Posts

    3
  • Joined

  • Last visited

Adamm99's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you Barand for your help. I have write the code again and works, it seems that I forgot to put name='filestoupload[]'. But there is one last problem, the code does not insert for example 1.jpg , 2 .jpg , 3.jpg in the same row, but it creates 3 different rows and I don't want that. Here is my new code : <?php include "db.php"; if(!empty($_FILES['filestoUpload']['name'])){ foreach($_FILES['filestoUpload']['name'] as $key => $val){ $name = $_FILES['filestoUpload']['name'][$key]; $tmp_loc = $_FILES['filestoUpload']['tmp_name'][$key]; $size = $_FILES['filestoUpload']['size']; $type = $_FILES['filestoUpload']['type']; $fileExt = explode('.', $name); $fileActExt = strtolower(end($fileExt)); $allowed = ['jpg', 'jpeg', 'png']; if(in_array($fileActExt, $allowed)){ $query = "INSERT INTO list(images) VALUES ('$name')"; $result = mysqli_query($conn, $query); } else { echo "This is not an image"; } } }
  2. Sorry about the photo, I did not know. Well, I am not confused about $_FILES, because like I said, the code works to upload only 1 image. I know what that code does, I do not understand why the loop does not work with it, and that is why I need help.
  3. Hello, I am new to PHP coding, and I have some issues trying to upload multiple images into database. The code works only for 1 image, but when I try to add foreach, I receive this message: Warning: Invalid argument supplied for foreach() . Can anyone help me ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.