Home > Article > Backend Development > How to save the path when uploading multiple images in PHP
1. Create a test database and create a data table named list in it to save the path of the picture. Path is the field that saves the path of the picture.
2. Create a new html file, named index.html, create a form in the file, and create an upload button in it. It should be noted that the upload button should be added with multiple to allow multiple images to be uploaded at the same time. The action of the form form is set to the upload.php file submitted to the server
3. Create the upload.php file to receive the uploaded images and save them in the database. First, connect to the database. The code is as follows:
#4. Write code to create a folder picture to save uploaded pictures, which is in the same directory as upload.php.
5. Write code to upload the received pictures using the move_uploaded_file() method. Because there are multiple pictures, use the foreach method to traverse the uploaded pictures and upload them separately. and insert into database.
6. Run the index.html file in the browser to upload images, for example, upload 3 images.
Execution results:
PHP uploads multiple pictures, the pictures are uploaded to the folder, and the picture path is saved in the database.
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to save the path when uploading multiple images in PHP. For more information, please follow other related articles on the PHP Chinese website!