如何从数据库中查找文件名


How to find a file name from the database

我的html中有一个文件列表,我已经从文件名中删除了目录ImageFiles/。例如,文件名如下所示:

tulips.png
koala.png
jellyfish.png

现在,如果用户单击其中一个文件名,那么我想从数据库中检索该文件,但在数据库中,所有文件都包含文件名开头ImageFiles/目录。因此,在数据库中,文件如下所示:

ImageFiles/tulips.png
ImageFiles/koala.png
ImageFiles/jellyfish.png

我的问题只是如何完成 WHERE 子句以便从数据库中检索正确的文件?例如,如果我正在寻找文件tulips.png,如何使查询能够从数据库中找到ImageFiles/tulips.png并且仅找到此文件?

下面是 mysqli 查询:

$getimage = $_GET['filename'];
    $imagequery = "SELECT ImageFile FROM Image WHERE (ImageFile = ?)";
            if (!$imagestmt = $mysqli->prepare($imagequery)) {
            // Handle errors with prepare operation here
    }

    // Bind parameter for statement
    $imagestmt->bind_param("s", $getimage);
    // Execute the statement
    $imagestmt->execute();

只需将目录名称附加到 $getimage 变量

$getimage = 'ImageFiles/' . $_GET['filename'];