如何使用PHP将图像插入数据库[关闭]

如何使用PHP将图像插入数据库[关闭]

问题描述:

I'm wanting to allow a person to upload an image to the website that I'm making and I don't know how to do it. I know how to make the HTML form but after that, I don't have a clue. I have made the database and I'm wanting to do it in PHP.

我想让一个人将图片上传到我正在制作的网站,我不知道 我知道怎么做。 我知道如何制作 HTML code>表格,但在那之后,我没有线索。 我已经创建了数据库,我想在 PHP code>中完成它。 p> div>

Generally the best way to do this, is to upload the file to your server, and then store the path to it in the database.

File Upload: http://php.net/manual/en/features.file-upload.php

You need to choose a database, MySQL is a common and free option:

https://www.mysql.com/

As mentioned in comment below, (I haven't used it before but had a read and looks like a better option) https://mariadb.com/

PDO (recommended library to use with several types of databases): http://php.net/manual/en/book.pdo.php

Note that there are many security considerations when letting people upload files to your server: https://security.stackexchange.com/questions/32852/risks-of-a-php-image-upload-form/32853#32853

All in all, it may be longer than you think before your friend is uploading that file - but it will be worth it