取消关联图像与 PHP 的链接



我正在尝试取消链接与mysql表记录ID链接的指定图像。运行此脚本时出现内部服务器错误,

查询:

我有两个相机in_cam和out_cam文件夹,我正在尝试将图像从in_cam交换到out_cam我的脚本将图像从in_cam复制到out_cam但图像不会在in_cam中删除。

 Put the entry into the other table
            $sql = "INSERT INTO $newCamTable (plate, nread, datetime, millisecs, nationality, image_name,image) SELECT plate, nread, datetime, millisecs, nationality, image_name,image  FROM $camTable $
            logit($sql);
            $result = $conn->Execute($sql);
            if (!$result)
              {
                print $conn->ErrorMsg();
              }
            $sql = "SELECT id FROM $newCamTable ORDER BY id DESC";
            $result = $conn->Execute($sql);
            if (!$result)
              {
                print $conn->ErrorMsg();
              }
            $row = $result->fields;
            $newId = $row['id'];
            $sql = "UPDATE $newCamTable SET name="$new_cam_name", camera_id="$new_cam_id" WHERE id="$newId"";
            logit($sql);
            $result = $conn->Execute($sql);
            if (!$result)
              {
                print $conn->ErrorMsg();
              }
    This is what I AM TRYING TO DO.
            sql = """SELECT id FROM  $camTable where id = "$tableEntryId"  LIMIT 1";
            logit($sql);
            $result  = $conn->Execute($sql);
            $id =  etCommonGetImagePath($conn, $camName, $id) {
            $serverDir = $_SERVER['DOCUMENT_ROOT'];
            $imagesTop = "/cam_images";
            $idArray = str_split(strval($id));
            $idString = implode('/', $idArray);
            $webPath = $imagesTop . "/" . $camName . "/" . $idString . ".jpg";
            $full_path = $serverDir . $webPath;
            if (file_exists($full_path)) {
            unlink($idString);
            }*/

            // Delete the entry from the camera table
            $sql = "DELETE FROM $camTable WHERE id="$tableEntryId" LIMIT 1";
            logit($sql);
            $result = $conn->Execute($sql);
您必须

使用服务器上的路径来删除图像,而不是URL。

unlink('/var/www/test/folder/images/image_name.jpeg');

以下内容应该会有所帮助

realpath — 返回规范化的绝对路径名 is_readable — 告知文件是否存在且可读 取消链接 — 删除文件

通过 realpath 运行您的文件路径,然后检查返回的路径是否存在,如果存在,请取消链接。

最新更新