gpt4 book ai didi

php - 我的图像未从文件夹中删除

转载 作者:行者123 更新时间:2023-11-29 22:40:45 24 4
gpt4 key购买 nike

我正在尝试从图像文件夹和数据库中删除图像。在我的脚本中,它从数据库中删除图像,但不会从图像文件夹中删除。

这是我到目前为止的代码:

if ((isset($_POST['imageId'])) && (is_numeric($_POST['imageId'])) ) { // Form submission.
$imageId = (int)$_POST['imageId'];

// fetch the selected images to delete
$query = " SELECT image_id, member_id, image
FROM image_info
WHERE image_id = ?";

$stmt = $mysqli->prepare($query);

if ($stmt) {
$stmt->bind_param('i', $imageId);
$stmt->execute();
$stmt->store_result();
$numrows = $stmt->num_rows;

if ($numrows == 1) {
$stmt->bind_result($image_id, $member_id, $image);

// define constant for upload folder
//define('UPLOAD_DIR_2', "images/slider/$member_id");

// Fetch all the records:
while ($stmt->fetch()) {
if(file_exists("images/slider/$member_id/".$image)) {
unlink("images/slider/$member_id/". $image); // delete file from folder
//echo UPLOAD_DIR_2;
} elseif(is_dir($image)) {
rmdir($image); // or system("rm -rf " . escapeshellarg($dir));
}
}

// Make the delete query:
$q = 'DELETE FROM image_info WHERE image_id= ? LIMIT 1';
$stmt = $mysqli->prepare($q);
$stmt->bind_param('i', $imageId);

// Execute the query:
$stmt->execute();

if ($stmt->affected_rows == 1) {
$success = "The slideshow image Deleted successfully.";
echo $successAlert;
}
$stmt->close();
unset($stmt);
}
}
}

谁能告诉我这有什么问题吗?希望有人可以帮助我。

谢谢。

最佳答案

请尝试这样,

$path = $_SERVER['DOCUMENT_ROOT']."/images/slider/".$member_id."/".$image;
unlink($path);

更新:

$path = dirname($_SERVER["SCRIPT_FILENAME"])."/images/slider/".$member_id."/".$image;
unlink($path);

关于php - 我的图像未从文件夹中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29361352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com