php - 将图像路径存储到数据库中

标签 php mysql image

我有以下代码将图像的路径存储到数据库中。

文件路径未存储到数据库中。虽然图片名称是?

知道这是为什么吗?

  <?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"/>

最佳答案

你需要指定它:

/* 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...

那么,您在数据库中存储的路径将为 = "$uploads_dir/$name"

关于php - 将图像路径存储到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26851790/

相关文章:

php - FPDF 错误 : Missing or incorrect image file

php - MySQL 从两个不同的表中选择唯一值?

sql - MySQL 错误 : ON DUPLICATE KEY UPDATE, 列计数与行的值计数不匹配

MySQL 给出错误的查询结果

html - 无法删除图像上的边框 - css

image - 如何在 Windows 上安装 freeimage.dll?

jquery - 预加载隐藏的 CSS 图像

javascript - 为什么我的 JQuery ReplaceWith() 不工作?

php - 如何在 Yii2 中获取视频文件输入的持续时间、大小和维度?

php - 不同的在sql查询中不起作用