Home  >  Article  >  Backend Development  >  How to save the path when uploading multiple images in PHP

How to save the path when uploading multiple images in PHP

王林
王林Original
2019-10-15 17:55:362226browse

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.

How to save the path when uploading multiple images in PHP

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

How to save the path when uploading multiple images in PHP

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:

How to save the path when uploading multiple images in PHP

#4. Write code to create a folder picture to save uploaded pictures, which is in the same directory as upload.php.

How to save the path when uploading multiple images in 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.

How to save the path when uploading multiple images in PHP

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.

How to save the path when uploading multiple images in PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn