[英]How to delete file from directory using class
我試圖從數據庫中刪除數據時從文件夾中刪除文件。 我上過課。 我收到以下錯誤:
調用未定義的函數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;
}
使用PHP代碼
unlink()
函數為刪除文件設置全拍
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.