Im trying to delete a file from folder while deleting data from database. I have used a class. I get the following error:
Call to undefined function getCodeName()
//This function is to get the file name from the database
public static function getCodeName($product_id) {
$db = Database::getDB();
$query = "SELECT * FROM products WHERE productID = '$product_id'";
$result = $db ->query($query);
$row = $result->fetch();
$product = new Product ($row['productCode']);
return $product;
}
//Delete file from folder and other data from database
public static function deleteProduct($product_id) {
$fileName = getCodeName($product_id);
$dir = "../images/";
unlink($dir.DIRECTORY_SEPARATOR.$fileName);
$db = Database::getDB();
$query = "DELETE FROM products
WHERE productID = '$product_id'";
$row_count = $db->exec($query);
return $row_count;
}
Use php code
unlink()
function set full pat for delete file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.