簡體   English   中英

如何顯示要使用PHP取消鏈接刪除的圖像

[英]How to display images to delete using PHP Unlink

我有一個腳本,可以使用PHP從文件夾中刪除圖像。

問題是圖像未顯示在頁面上。

我的代碼如下

<?php
// directory separator
defined("DS")
    || define("DS", DIRECTORY_SEPARATOR);

// root path
defined("ROOT_PATH")
    || define("ROOT_PATH", realpath(dirname(__FILE__)));

// upload folder directory
defined("UPLOAD_DIR")
    || define("UPLOAD_DIR", "uploads");

// path to the upload folder
defined("UPLOAD_PATH")
    || define("UPLOAD_PATH", ROOT_PATH.DS.UPLOAD_DIR);


function getAllFiles($folder = null) {
    if(!empty($folder) && is_dir($folder)) {
        if($handle = opendir($folder)) {
            $out = array();
            while($file = readdir($handle)) {
                if(is_file($folder.DS.$file)) {
                    $out[] = $file;
                }
            }
            closedir($handle);
            return $out;
        }
        return false;
    }
    return false;
}

$files = getAllFiles(UPLOAD_PATH);

if (!empty($_POST['file'])) {
    foreach($_POST['file'] as $file) {
        unlink(UPLOAD_PATH.DS.$file) or die("Failed to <strong class='highlight'>delete</strong> file");
    }
    header("location: " . $_SERVER['REQUEST_URI']);
}
?>

<?php if (!empty($files)) { ?>

<form name="form1" method="post">
    <?php foreach($files as $key => $file) { ?>
        <label for="file_<?php echo $key; ?>">
            <input type="checkbox" name="file[]" id="file_<?php echo $key; ?>" value="<?php echo $file; ?>" /> 
            <?php echo $file; ?>
        </label>
    <?php } ?>
    <input type="submit" name="delete" value="Delete" />
</form>

該代碼可以很好地刪除圖像,但不會在頁面上顯示圖像。

非常感謝您的幫助。

謝謝

我認為圖像仍在瀏覽器緩存中,因此刪除緩存將導致看不到任何已刪除的圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM