图像上传脚本在PHP中 [英] image upload script in php
问题描述
我在想什么,我可以存储图像与用户的图像名称 - 身份证,但在这种情况下,将这些图像存储评论是困难的。
有没有更好的方法?
一个数据库?
如果不是:
设置一个数据库来存储用户,然后创建一个逻辑连接用户:
用户:
| ---------------------------------- -----
| UserId用户名密码|
| ---------------------------------------
| 1 Robert 3j9745t3 |
| 2 Paul 03945u30 |
| ---------------------------------------
$ p
$ b $ pre $--------------------------------------------------
| ImageID UserId Desc ImageHash |
| --------------------------------------------- ---- |
| 1 1 Some Desc 87ytr8d23yr |
| 2 1 Some Desc 5uty4095u40 |
| --------------------------------------------- ---- |
然后将图像存储在图像目录中,如 87ytr8d23yr.png
,然后你可以做一个PHP查询就像这样
$ userid = 1;
$ sql =SELECT * FROM WHERE UserId =。 (int)$ userid。 ORDER BY ImageID LIMIT 10;
if($!$($ resource = mysql_query($ sql)))
{
while($ imageRow = mysql_fetch_object($ resource))
{
if(file_exists('imageDir /'。$ imageRow-> ImageHash。'.png'))
{
//做任何事情。
}其他
{
//删除行并通知用户由于某种原因图片已被删除。
$ b 你也只需要做一个评论表,并添加ImageId,当用户评论一个图像只是将图像添加到注释行,以便您可以跟踪它。
In my application a user can create his/her photo album.
My question is how can I upload images specific to that user-id who has uploaded them? This means there should be some criteria that will indicate that these images belong to this user.
What I was thinking that I can store images with the image name of the user-id, but in that case it would be difficult to store comments along with these images.
Is there any better way?
解决方案 Are you not using a database?
If no:
Set up a database to store the users, then create a logical connection between the iamges and the users.
for instance
Users:
|---------------------------------------
| UserId Username Password |
|---------------------------------------
| 1 Robert 3j9745t3 |
| 2 Paul 03945u30 |
|---------------------------------------
Images:
|--------------------------------------------------
| ImageID UserId Desc ImageHash |
|-------------------------------------------------|
| 1 1 Some Desc 87ytr8d23yr|
| 2 1 Some Desc 5uty4095u40|
|-------------------------------------------------|
Then store the images on your images directory like 87ytr8d23yr.png
and then you can do a php query like so
$userid = 1;
$sql = "SELECT * FROM Images WHERE UserId = " . (int) $userid . " ORDER BY ImageID LIMIT 10";
if(false !== ($resource = mysql_query($sql)))
{
while($imageRow = mysql_fetch_object($resource))
{
if(file_exists('imageDir/' . $imageRow->ImageHash . '.png'))
{
//Do whatever.
}else
{
//Delete the row and inform the user that the picture has been deleted for some reason.
}
}
}
Also you just have to do a Comments table and add ImageId, and when a user comments on an image just add the image into the comment row so you can trace it.
这篇关于图像上传脚本在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!