I can not figure out the code for PHP. The whole point is that you need to take information from the MS SQL server database and upload it to the site. The problem is as follows. The first photo is loaded without any problems, but if the user adds or changes it, the script does not update the photo in any way. My code is:

// Generate Picture and Thumbnail if (is_null($row['image_data'])) { $imgPath = ""; } else { $existQuery = "SELECT * FROM imagetrack WHERE pictureID = '" . $row['animal_id'] . "'"; $existResult = mysql_query($existQuery); $existCheck = mysql_fetch_array($existResult); if ($existCheck['id'] && $existCheck['stampDate'] == $row['stamp'] && file_exists("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/thumbs/".$row['animal_id'].".jpg")) { $imgPath = $row['animal_id'].".jpg"; } else { if ($existCheck['id'] && $existCheck['stampDate'] != $row['stamp']) { unlink("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/".$row['animal_id'].".jpg"); unlink("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/thumbs/".$row['animal_id'].".jpg"); } $imgPath = $row['animal_id'].".jpg"; createImage($animalType, $animalStatus, $row['image_data'], $row['animal_id']); createThumbs("petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/","petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/thumbs/",150); if (!ftp_put($ftp_conn, $ftp_root . strtolower($animalType) . "/" . strtolower($animalStatus) . "/" . $imgPath, $site_root . strtolower($animalType) . "/" . strtolower($animalStatus) . "/" . $imgPath, FTP_BINARY) || !ftp_put($ftp_conn, $ftp_root . strtolower($animalType) . "/" . strtolower($animalStatus) . "/thumbs/" . $imgPath, $site_root . strtolower($animalType) . "/" . strtolower($animalStatus) . "/thumbs/" . $imgPath, FTP_BINARY)) { if (unlink("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/".$row['animal_id'].".jpg")) { $logMsg = "Error uploading, unlinking image for ".$row['animal_id']."."; $logQuery = "INSERT INTO log (date, message) VALUES(".date('dmY h:i').", $logMsg)"; mysql_query($logQuery); } if (unlink("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/thumbs/".$row['animal_id'].".jpg")) { $logMsg = "Error uploading, unlinking thumb image for ".$row['animal_id']."."; $logQuery = "INSERT INTO log (date, message) VALUES(".date('dmY h:i').", $logMsg)"; mysql_query($logQuery); } } else { if ($existCheck['stampDate'] != $row['stamp']) { $delQuery = "DELETE FROM imagetrack WHERE pictureID = '". $row['animal_id'] . "'"; mysql_query($delQuery); } $writeQuery = "INSERT INTO imagetrack (pictureID, stampDate) VALUES ('". $row['animal_id'] . "', '" . $row['stamp'] . "')"; mysql_query($writeQuery); } } $logQuery = "INSERT INTO log (date, message) VALUES (".date('dmY h:i').", 'Animal ".$row['animal_id']." processed successfully')"; mysql_query($logQuery); } $i++; if (is_null($row['feet'])) { $declawed = "No"; } else { $declawed = $row['feet']; } 

    1 answer 1

      if ($existCheck['id'] && $existCheck['stampDate'] == $row['stamp'] && file_exists("./petUploads/images/".strtolower($animalType)."/".strtolower($animalStatus)."/thumbs/".$row['animal_id'].".jpg")) { $imgPath = $row['animal_id'].".jpg"; } else { 

    I do not see in your code block, which is responsible for updating, adding a new or changing an existing photo. If there is a photo, then the path to the picture returns. Nothing else happens in this case.

    • I would like to add it then, can you set the path right?) - Maya
    • First of all, the code is very tangled, it is difficult to change anything in it without breaking anything. At first, I would single out certain functions from it - Ilya Kovalyov
    • getImagePath, removeImage, uploadImage, shouldAddNewImage. What functions do I think is understandable by name. Make sure the code is working and nothing is broken. And then just add a new logic - if (shouldAddNewImage ()) {removeImage (); uploadImage (); getImagePath ();); Something like this. - Ilya Kovalyov