php - 如何创建从目录中删除多个文件/图像的功能?
问题描述
这就是我目前尝试设置该功能的方式:
/** Deletes any images and associated thumbnails */
function deleteImages() {
$_POST['deleteImage'] = array();
$selectedImages = $_POST['deleteImage'];
foreach($selectedImages as $selectedImage) {
unlink(GALLERY_IMG_PATH."/".GALLERY_IMG_FULLSIZE."/".$selectedImage);
unlink(GALLERY_IMG_PATH."/".GALLERY_IMG_THUMB."/".$selectedImage);
}
}
我正在使用以下内容在图库中显示表单和图像:
<form action="Admin?admin_action=<?php echo $results['formAction']?>"
method="post" enctype="multipart/form-data" name="formUploadFile">
<?php
$directory = "GALLERY_IMG_PATH."/".GALLERY_IMG_FULLSIZE."/";
$images = glob("$directory*.{jpg,png,webp}", GLOB_BRACE);
foreach($images as $image) {
$filepath = $image;
$filename = pathinfo($filepath, PATHINFO_FILENAME);
$basename = pathinfo($filepath, PATHINFO_BASENAME);
?>
<label class="centered_label" for="deleteImage" title="Click here to delete
current image.">Delete Image:<input type="checkbox" name="deleteImage"
id="deleteImage" value="<?php echo $basename?>"></label>
<img id="postImage" src="<?php echo $image;?>" title="<?php echo
preg_replace('/\_/', ' ',$filename)?>." alt="<?php echo
preg_replace('/\_/', ' ',$filename)?>.">
<?php } ?>
<label class="centered_label" for="images[]" title="This field is to upload
an image/images for the Image Gallery.">Select image/images to
upload</label>
<input type="file" name="images[]" id="images" accept="image/*"
multiple="multiple" placeholder="Upload an image/images.">
<input type="submit" name="uploadImages" value="UploadImages/SaveChanges"
title="Click/tap here to save/upload image(s)/save changes. You will be
returned to Admin Homepage.">
<input class="cancel" type="button" name="cancel" value="Cancel"
title="Click/tap here to cancel and exit Image Gallery Uploader. You will
be returned to Admin Homepage." formnovalidate onclick="history.go(-1)">
</form>
我在这里编辑了我的原始帖子,以反映我如何尝试删除图库编辑表单的图像。我似乎无法让它工作。但是,当我单独选择一个时,我可以让它工作,在这种情况下,全尺寸和缩略图都会被删除。这就是我想要的每次删除。我遇到的问题是当我尝试选择多个图像时。以上是尝试的deleteImages function()我无法开始工作。
解决方案
推荐阅读
- javascript - 如何在不发生内存泄漏的情况下添加 auth listener firebase
- javascript - 遍历我的主目录时导致 EPERM 错误的原因是什么?
- kotlin - 请向我解释这个 kotlin 声明?
- selenium - Selenium Webdriver:为什么它不能找到某个类的所有 HTML 元素?
- html - 当我将 CSS 文件上传到我的网站时,网站忽略了我的 h3 标签的所有样式选项
- ios - Swift - 如何更新自定义 MKAnnotation 标注中的数据?
- reactjs - React 中 .then 和 async/await 之间的区别
- python - 带有值检查的生成器表达式
- swift - 缺少自动布局的 Xcode 11 pin 菜单(在 Main.storyboard 下)-仅在此项目上
- express - 大于 ~7mb 的文件会抛出“未收到响应”。在 IBM Watson Speech-To-Text 异步 createJob 调用上