简体   繁体   English

图像不显示

[英]Images Not Displaying

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. I图像被删除但不显示。

My code is: 我的代码是:

<?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", "../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; ?> />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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