简体   繁体   中英

Upload Images to database php

I have a doubt.. I´m doing in php a page to buy and sell cars, and I have a form that has 5 input files(one for each image). The question is: Do I have to do 5 times the same file to upload each image separately or with one file that executes the code for the 5 images it´s ok?

You can assign each files with an id from 1-5. Like this $_FILES['filename']['#id'] and then use a for loop to upload them from 1-5. Hope this helps. There is a similar question here. Multiple image upload using php

As smuhero has said above, but you could also edit your database to have 5 seperate fields (one for each picture) then if a picture is uploaded you could either store the image directly in the database (takes a lot of space as you have to convert the image to Base64 data and then insert) or leave the location of the picture in the field.

Of course you'd have to ensure that you securely protect against incorrect files being called by malicious users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM