我正在尝试将2张照片保存到我的MySQL数据库中。我只能看到数据库中的2张照片中的一张(即它的名字),但我看到我存储照片的文件夹中的2张照片。 (附上数据库外观的图片。)当我尝试显示2张照片时,我只看到我在数据库中看到的那张照片。这有什么问题?
上传照片的Html代码
<input type="file" id="_photo" name="_photo[]" multiple="multiple">
<input type="button" id="add_more" class="" value="Add More Files"/>
将照片保存在数据库和文件夹中的代码
if (!empty($_FILES['_photo']['name'][$i])) {
if ($_FILES['_photo']['type'][$i] == 'image/jpeg') {
$upload_folder = "./profile_pix/";
$pic_name = time() . ".jpg";
$pic_path = $upload_folder . $pic_name;
require_once "include/resize.php";
if (move_uploaded_file($_FILES['_photo']['tmp_name'][$i], $pic_path)) {
$image = new Resize($pic_path);
$image->resizeImage(180, 180, 'crop');
$image->saveImage($pic_path);
//thumbnail
$image = new Resize($pic_path);
$image->resizeImage(50, 50, 'crop');
$image->saveImage($upload_folder . "thumb/" . $pic_name);
}
}
}
else {
$pic_name="default_house.png";
}
$sql = "INSERT INTO offers
(accommodation, school, date, available, member_id, photo, )
VALUES
(:accommodation, :school, :date, 'yes', :member_id, '$pic_name', )";
$query = $db->($sql, array(..........));
显示上传照片的代码
$sql = "SELECT * FROM myDatabase";
foreach ($db->query($sql) AS $result){
echo "
<img src='profile_pix/{$result['photos']}' width = '30' height ='30px' style=' margin-top:8px;'/>
";
}enter image description here
答案 0 :(得分:0)
尝试以下操作,希望它能够正常运行。请记住,您的专栏是photo
,而不是photos
。
<?php
$sql = "SELECT * FROM myDatabase";
$sqlres = mysql_query($sql);
foreach ($sqlres AS $result){
echo "<img src='profile_pix/".$result['photo']." width = '30' height ='30px' style=' margin-top:8px;'/>";
}
?>