doubo9799 2019-04-28 02:57
浏览 134
已采纳

图像已成功上传到数据库并显示在目录中,但不会显示在php页面上

Images are successfully uploaded to database and display in a directory but it won't display on the php page. Images show up as broken images on the php page. Help me make them display on the php page. I followed a tutorial and watched it many times to make sure there are no errors causing the broken images. Been trying to fix it for days but it won't display images. I'm using XAMPP on a Mac OS. Please look through my codes and let me know why it won't display the images on php.

marketplace_upload.inc.php starts here:


if (isset($_POST['submit'])) {

    $newFileName = $_POST['filename'];

    if (empty($newFileName)) {
        $newFileName = "gallery";

        } else {
            $newFileName = strtolower(str_replace(" ", "-", $newFileName));
        }

        $imageTitle = $_POST['filetitle'];
        $imagePrice = $_POST['fileprice'];


        $file = $_FILES['file']; 

        $fileName = $file["name"];
        $fileType = $file["type"];
        $fileTempName = $file["tmp_name"];
        $fileError = $file["error"];
        $fileSize = $file["size"];


        $fileExt = explode(".", $fileName);
        $fileActualExt = strtolower(end($fileExt));

        $allowed = array("jpg", "jpeg", "png");

        if (in_array($fileActualExt, $allowed)) {
            if ($fileError === 0) {
                if ($fileSize < 2000000) {
                    $imageFullName = $newFileName . "." . uniqid("", true) . "." . $fileActualExt;
                    $fileDestination = "../img/gallery/" . $imageFullName;

                    include_once "dbh.inc.php";

                    if (empty($imageTitle) || empty($imagePrice)) {
                        header("Location:../gallery.php?upload=empty");
                        exit();
                    } else {
                        $sql = "SELECT * FROM gallery;"; 
                        $stmt = mysqli_stmt_init($conn);
                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                            echo "SQL statement failed!";
                        } else {
                            mysqli_stmt_execute($stmt);
                            $result = mysqli_stmt_get_result($stmt);
                            $rowCount = mysqli_num_rows($result);
                            $setImageOrder = $rowCount + 1;

                            $sql = "INSERT INTO gallery (titleGallery, priceGallery, imgFullNameGallery, orderGallery) VALUES (?, ?, ?, ?);";
                        }
                            if (!mysqli_stmt_prepare($stmt, $sql)) {
                            echo "SQL statement failed!";
                        } else {
                            mysqli_stmt_bind_param($stmt, "ssss", $imageTitle, $imagePrice, $imageFullName, $setImageOrder);
                            mysqli_stmt_execute($stmt);

                            move_uploaded_file($fileTempName, $fileDestination);
                            header("Location: ../gallery.php?upload=success");
                            }
                        }
                    }
                } else {
                    echo "File size is too big!";
                    exit();
                }
            } else {
                echo "You had an error!";
                exit();
            }
        } else {
            echo "You need to upload a proper file type!";
            exit();
        }

Screenshot of gallery.php codes where images are supposed to be displayed. It won't let me paste the codes here.

I would like any uploaded images on my upload website to display in localhost too.

  • 写回答

1条回答 默认 最新

  • dongmi5020 2019-04-29 03:03
    关注

    Thank you to everyone who helped me or tried to help me. I finally solved the problem. The reason why my images weren't displaying on my php page is because I hadn't change the permissions. Once I changed the permissions to read and write my codes started doing what I want them to do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 无网格伽辽金方法研究裂纹扩展的程序
  • ¥15 如何用数码管显示学号(相关搜索:单片机)
  • ¥15 错误于library(org.Hs.eg.db): 不存在叫‘org.Hs.eg.db’这个名称的程序包,如何解决?
  • ¥60 求一个图片处理程序,要求将图像大小跟现实生活中的大小按比例联系起来的
  • ¥50 求一位精通京东相关开发的专家
  • ¥100 求懂行的大ge给小di解答下!
  • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
  • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
  • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
  • ¥100 华为手机私有App后台保活