gpt4 book ai didi

php - 如何使用SQL将图像存储到文件中?

转载 作者:行者123 更新时间:2023-11-29 19:01:29 25 4
gpt4 key购买 nike

<?php

if(isset($_POST['hour'])&&isset($_POST['day'])){

//the path to store the uploaded image.
$target = "images/".basename($_FILES['image']['name']);

$db = mysqli_connect("localhost","root","","a_database");

$image = $_FILES['image']['name'];
$carmodel = $_POST['carmodel'];
$cartype = $_POST['cartype'];
$hour = $_POST['hour'];
$day = $_POST['day'];

$query = "INSERT INTO `cardetails` (`image`, `carmodel`, `cartype`, `hour`, `day`) VALUES ('".$image."', '".$carmodel."', '".$cartype."', '".$hour."', '".$day."')";
mysqli_query($db,$query);//stores the data

//move uploaded image into the folder.
if(move_uploaded_file($_FILES['image']['tmp_name'],$target)){
header('Location:upload_success.php');
}else{

header('Location:upload_fail.php');
}

}else{
echo ' ';
}

?>


<div class="col-lg-offset-4">
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div class="form-group row">
<input type="file" name="image">
</div>

<div class="form-group col-lg-4 row">
<label> Car Model </label>
<select name="carmodel" class="form-control" >
<option value="Myvi">Myvi</option>
<option value="Vios">Vios</option>
<option value="Lambo">Lambo</option>
</select>
</div>

<div class="form-group row col-lg-offset-4">
<label> Car Type </label>
<input type="radio" name="cartype" value="Auto">Auto
<input type="radio" name="cartype" value="Manual"> Manual
</div>

<div class="form-group">
<input type="text" name="hour" placeholder="$/hour">
</div>

<div class="form-group">
<input type="text" name="day" placeholder="$/day">
</div>

<div class="form-group">
<button type="submit">Upload</button>
</div>

</form>

</div>

我已成功将数据插入带有图像名称的数据库,但图像似乎没有上传到我的图像文件中,可能出了什么问题?根据上面的代码,调用upload_fail.php。如果使用 $_POST['image'] 设置,则不会发生任何事情。

最佳答案

我认为,您没有足够的权限写入 images 目录。 images 目录本身是否存在?

如果您想知道出了什么问题,您可以在 php 文件的开头启用错误报告,例如:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
...

关于php - 如何使用SQL将图像存储到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43846666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com