图像不会保存到项目文件夹

时间:2019-01-29 17:23:32

标签: php

我有一个项目的图像上传索引。创建到图像的链接,并将其保存到phpMyAdmin DB,并且该图像应保存到项目文件中的/ image文件夹中。索引将链接/目录访问权限保存在数据库中,但是图像本身未保存。因此,基本上,我的图像文件夹中有一个指向空白图像的链接!

在从本地主机转移到黑夜服务器之前,代码没有问题。

任何建议将不胜感激。

我已经使用BLOB而不是文本数据库中的图像尝试和效果不好。

我已获得在FileZilla中进行读/写访问的权限。

我已更正所有数据库连接和文件路径。

NameError: name 'OAUTH_TOKEN' is not defined

我希望这一行会将文件提交到/ images文件夹

<?php

   // Create database connection

   $db = mysqli_connect("*HOST*", "*USERNAME*", "*PASSWORD*", "*DB_NAME*");

  // Initialize message variable
  $msg = "";

  // If upload button is clicked ...
  if (isset($_POST['upload'])) {
  // Get image name
$image = $_FILES['image']['name'];
// Get text

$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
 $regplate = $_POST['regplate'];

// image file directory
$target = "/wwwroot/*DOMAIN_NAME*/images/".basename($image);

$sql = "INSERT INTO images (regplate, image, image_text) VALUES ('$regplate', '$image', '$image_text')";
// execute query
mysqli_query($db, $sql);

if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
    $msg = "Image uploaded successfully";
   }else{
    $msg = "Failed to upload image";
    }
    }
   $result = mysqli_query($db, "SELECT * FROM images");
  ?>

1 个答案:

答案 0 :(得分:-1)

无需指定文件夹的完整路径

<?php

       // Create database connection

       $db = mysqli_connect("*HOST*", "*USERNAME*", "*PASSWORD*", "*DB_NAME*");

      // Initialize message variable
      $msg = "";

      // If upload button is clicked ...
      if (isset($_POST['upload'])) {
      // Get image name
    $image = $_FILES['image']['name'];
    // Get text

    $image_text = mysqli_real_escape_string($db, $_POST['image_text']);
     $regplate = $_POST['regplate'];

    // image file directory
    $target = "./images/".basename($image);

    $sql = "INSERT INTO images (regplate, image, image_text) VALUES ('$regplate', '$image', '$image_text')";
    // execute query
    mysqli_query($db, $sql);

    if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
        $msg = "Image uploaded successfully";
       }else{
        $msg = "Failed to upload image";
        }
        }
       $result = mysqli_query($db, "SELECT * FROM images");
      ?>