开发者

Images Not Displaying

开发者 https://www.devze.com 2023-02-20 00:11 出处:网络
All I want is that the images are displayed nothing else please. I have been working on a different script but have the same problem.

All I want is that the images are displayed nothing else please.

I have been working on a different script but have the same problem.

I images are deleted but not displayed.

My code is:

<?php
// directory separator
defined("DS"开发者_StackOverflow中文版)
    || define("DS", DIRECTORY_SEPARATOR);

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

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

// 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 UPLOAD_DIR.DS.$file; ?>
            </label>
        <?php } ?>
        <input type="submit" name="delete" value="Delete" />
    </form>

<?php } ?>


The question is not clear to me but it appears you want to display the images in the form (beside each "delete" checkbox) so the user can see what they are deleting?

If so, can you try changing

<?php echo UPLOAD_DIR.DS.$file; ?>

to

<img src=<?php echo UPLOAD_DIR.DS.$file; ?> />
0

精彩评论

暂无评论...
验证码 换一张
取 消