我试图取消链接与mysql表记录ID链接的指定图像。我可以删除mysql上的记录。运行此脚本时出现内部服务器错误,
查询:
我有两个摄像头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);
答案 0 :(得分:0)
您必须使用服务器上的路径删除图片,而不是网址。
unlink('/var/www/test/folder/images/image_name.jpeg');
答案 1 :(得分:0)
以下内容应该有所帮助
realpath - 返回规范化的绝对路径名 is_readable - 判断文件是否存在且可读 unlink - 删除文件
通过realpath运行文件路径,然后检查返回的路径是否存在,如果存在,则取消链接。