我正在尝试为php中的一个类项目构建一个社交网站,我对如何构建照片库感到有些困惑。我感到困惑的是我应该如何存储图片和数据库结构来存储图片。任何帮助将不胜感激。
答案 0 :(得分:0)
有很多方法可以解决这个问题,但我会以最直接的方式给你。目标是让您了解基本步骤。
1- You should create a folder called 'images' under your root folder.
2- You upload the file to this folder. This tutorial shows you how :
http://www.w3schools.com/php/php_file_upload.asp
Note: you will want to save the file under a name of your choice. Be careful in chosing a unique name to avoid overwriting other files in the folder.
3- On the database side, you will just need to insert the PATH or URL of the file on your server.
4- In your view, you would insert the image this way :
<img src="<?php echo $image_path; ?>" alt="">
我希望你明白这个主意。祝好运!!!