如何从PHP中的数据库和文件夹中删除图像

时间:2019-01-27 03:16:50

标签: php pdo unlink

我有PHP代码,我试图从数据库中删除图像并上传文件夹。我研究了,似乎 就像我需要取消链接选项,但我对PHP还是不够了解 编码如何实现它。我拥有的代码将从 MySQL数据库就可以了,但是当我尝试添加上行代码时 破坏它,什么也不做。

我尝试添加以下内容:

$file_path = 'uploads/' . $_POST["images"];
if(unlink($file_path))

到下面的代码。

        //start PHP session
    session_start();

if (!isset($_SESSION['success']))
{
    header("Location: login_page.php");
    die();
}

// check if value was posted
if($_POST){

    // include database and object file
    include_once 'config/database.php';

    $file_path = 'uploads/' . $_POST["image"];
    if(unlink($file_path))
 {
    // delete query
    $query = "DELETE FROM dhospital WHERE id = ?";
    $stmt = $con->prepare($query);
    $stmt->bindParam(1, $_POST['object_id']);
 }
    if($stmt->execute()){
        // redirect to read records page and 
        // tell the user record was deleted
        echo "Record was deleted.";
    }else{
        echo "Unable to delete record.";
    }
}

我正在使用PHP-PDO-MySQL

0 个答案:

没有答案