[英]unlink associated image from php
我正在嘗試取消鏈接與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);
您將必須使用服務器上的路徑來刪除圖像,而不是URL。
unlink('/var/www/test/folder/images/image_name.jpeg');
以下應該有幫助
realpath-返回規范化的絕對路徑名is_read-告訴文件是否存在並且可讀取消鏈接-刪除文件
通過realpath運行文件路徑,然后檢查返回的路徑是否存在,如果存在,請取消鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.