Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to unlink specified image which is linked with mysql table record ID.
I can delete the record on mysql. I get Internal server error when i run this script,

Query:

I have two cameras in_cam and out_cam folders I am trying a function swap lane where the images from in_cam copies to out_cam. my script copies the images from in_cam to out_cam but the image is not deleted in the in_cam.

Put the entry into the other table
PHP
            $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);

            $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);

MYSQL RECORD

ID,       camera_id,  name,         plate,      nread,   datetime,                    millisecs,  nationlaity,image_name,image,checked
#
'542276', '38', 'HuddersfieldIN', 'YS63YPY', NULL, '2015-04-28 22:45:57', '648', 'GBR', 'YS63YPY-GBR_HuddersfieldIN_2015-04-28_22-45-57-648_UNKNOWN.jpg', ?, '0'

Image location - id String

/var/www/cam_images/HuddersfieldIN_anpr_vega/5/4/2/2/7/6.jpg


I am struggling hard to delete the image I don't know where am I going wrong.
Posted
Updated 29-Apr-15 16:35pm
v3
Comments
Mohibur Rashid 30-Apr-15 0:22am    
you are checking if $full_path exists and then trying to unlink $idString
the mishap is there. verify the filename with qualified path and then unlink it with that exact filename with qualified path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900