我有以下代码将图像的路径存储到数据库中。
文件路径未存储到数据库中。虽然图像名称是?
为什么会这样?
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
// escape variables for security
$ImageName = mysqli_real_escape_string($con, $_POST['imageName']);
//getting the filename of the image file.
$file_name = $_FILES['fileToUpload']['name'];
$sql="UPDATE images SET imageLoc = '$file_name', imageName = '$ImageName'
WHERE Username = '".$_SESSION["Username"]."'";
//$query = mysqli_query($con,$sql);
if (!mysqli_query($con,$sql)){
echo "error";
}
echo "yess";
mysqli_close($con);
?>
数据库连接正常。
由于
XHTML部分:
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
Name of Image: <input type="text" name="imageName"/>
答案 0 :(得分:0)
您需要指定它:
/* this->> */ $uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
/* then do this--> */ move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
因此,您将路径存储为$ uploads_dir 然后,您需要将文件移动到$ uploads_dir ...
那么,你在数据库中存储的路径将是=&#34; $ uploads_dir / $ name&#34;