我已经为客户制作了一个图片库,现在他希望有机会将图片上传到图库。所以我当然已经建立了一个登录系统,它运行得很好。我已经制作了一个快速上传表单,这有点工作 - 我只能上传一个文件,但我稍后会修复它。 (欢迎您也提供帮助) 我现在的问题是在我的画廊中获取我用fancybox制作的图像。怎么样?
我的画廊看起来像这样:
<div id="facader">
<a class="fancybox" rel="gallery1" title="Facader" href="images/facade1.jpg"><img src="images/facade.jpg" alt=""/></a>
<div class="hidden">
<a class="fancybox" rel="gallery1" title="Facader" href="images/facade2.jpg"><img src="images/facade2.jpg" width="221" height="166" alt=""/></a>
<a class="fancybox" rel="gallery1" title="Facader" href="images/facade3.jpg"><img src="images/facade3jpg" alt="" width="220" height="220"/></a>
<a class="fancybox" rel="gallery1" title="Facader" href="images/facade4.jpg"><img src="images/facade4.jpg" alt="" width="225" height="127"/></a>
</div>
</div>
(这只是六个类别中的一个)
我的上传表单如下:
<form action="upload.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image"><input type="submit" value="Upload">
</form>
<?php
//connect to database
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_database = "addina";
$db = mysqli_connect($db_host,$db_user,$db_password,$db_database) or die("Error - cant connect or find db");
//file
print_r($_FILES);
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select an image";
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "That's not an image.";
else {
if (!$insert = mysqli_query($db, "INSERT INTO image VALUES ('$image_name','$image')"))
echo "Problem uploading the image.";
else
{
$lastid = mysqli_insert_id();
echo "Image uploaded.<p />Your image:<p />IMAGE";
}
}
}
?>
我的数据库看起来像这样:
id int(11) unique null no AUTO_INCREMENT
name var(200) null no
images blob null no
非常感谢你的时间。