繁体   English   中英

如何使用类从目录中删除文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM