iPhone 照片上传在相册中相互覆盖
iPhone photo uploads overwrite each other in gallery
我有一个图片库,用户可以在其中将手机中的图片上传到数据库中,然后在我的图库页面上调用该数据库。每个条目在数据库中都有一个 ID、一个图像和一个描述。
这是导出图库的代码:
//include database connection
include 'mysqlconnect.php';
$sql="select * from images order by image desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
$image=$row ['image'];
$description=$row ['description'];
//call all images from DB
echo '<a href="'.$image.'" title="'.$description.'" style="background-image:url('.$image.');"></a>';
}
问题出在用户上传带有 iPhone 的照片时。因为 iPhones 总是将他们的图像保存为 "image.jpg",所以每次上传时它都会覆盖图库中以前的 iPhone 图像。我认为这是因为画廊只要求文件名。
有没有办法根据行 ID 调用图像?像 $image=$row['id','image'];
?
这样的东西
首先,如果上传了相同的图片名称,但您没有做出重命名的规定或使用独特的文件夹来使它们独一无二,那么这就是问题所在。
如果您想根据 ID 查看照片,请在查询中使用它。
即:
$sql="select * from images WHERE id='some_id' order by image desc";
"Is there a way to call for the images based on their row ID? Something like $image=$row['id','image']; ?"
不,这是无效语法:
$image=$row['id','image'];
您需要使用两个单独的 $row(s)
。
即:
$id = $row['id'];
$image=$row['image'];
旁注:您甚至可能不需要使用 WHERE
子句,只需使用 $row['id']
.
但是,如果您设置为仅根据特定用户显示图像,那么可以;使用 WHERE
子句,甚至使用基于会话用户名的会话。
重命名上传的文件:
请参阅以下内容以了解如何在上传时使用唯一名称:
- How to rename uploaded file before saving it into a directory?
您还在使用已弃用的 MySQL 库。最好转移到 mysqli_
或 PDO,因为它将从未来的 PHP 版本中删除。
参考文献:
我有一个图片库,用户可以在其中将手机中的图片上传到数据库中,然后在我的图库页面上调用该数据库。每个条目在数据库中都有一个 ID、一个图像和一个描述。
这是导出图库的代码:
//include database connection
include 'mysqlconnect.php';
$sql="select * from images order by image desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
$image=$row ['image'];
$description=$row ['description'];
//call all images from DB
echo '<a href="'.$image.'" title="'.$description.'" style="background-image:url('.$image.');"></a>';
}
问题出在用户上传带有 iPhone 的照片时。因为 iPhones 总是将他们的图像保存为 "image.jpg",所以每次上传时它都会覆盖图库中以前的 iPhone 图像。我认为这是因为画廊只要求文件名。
有没有办法根据行 ID 调用图像?像 $image=$row['id','image'];
?
首先,如果上传了相同的图片名称,但您没有做出重命名的规定或使用独特的文件夹来使它们独一无二,那么这就是问题所在。
如果您想根据 ID 查看照片,请在查询中使用它。
即:
$sql="select * from images WHERE id='some_id' order by image desc";
"Is there a way to call for the images based on their row ID? Something like $image=$row['id','image']; ?"
不,这是无效语法:
$image=$row['id','image'];
您需要使用两个单独的 $row(s)
。
即:
$id = $row['id'];
$image=$row['image'];
旁注:您甚至可能不需要使用 WHERE
子句,只需使用 $row['id']
.
但是,如果您设置为仅根据特定用户显示图像,那么可以;使用 WHERE
子句,甚至使用基于会话用户名的会话。
重命名上传的文件:
请参阅以下内容以了解如何在上传时使用唯一名称:
- How to rename uploaded file before saving it into a directory?
您还在使用已弃用的 MySQL 库。最好转移到 mysqli_
或 PDO,因为它将从未来的 PHP 版本中删除。
参考文献: