[英]PHP/HTML - issue with form handling - unlink() warning
I'm trying to allow user to delete images
from a folder on server through html form
and PHP
. 我试图允许用户通过
html form
和PHP
从服务器上的文件夹中delete images
。
Here's my html
form markup along with PHP script generating list images
from the folder mentioned before. 这是我的
html
表单标记以及PHP脚本从前面提到的文件夹中生成列表images
。 I've added checkboxes with path+filename as value
. 我添加了带有path + filename作为
value
复选框。
<form action="delete.php" method="POST">
<div id="formlist">
<?php
$path = ".";
$dh = opendir($path);
$i=1;
$images = glob($path."*.png");
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != ".." && $file != "index.php" && $file != "form.css" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {
echo "<div class='formshow'><a href='$path/$file' data-lightbox='Formularze' data-title='$file'><img class='formimg' src='$path/$file' width='500px'/></a><input type='checkbox' name='deleteform' value='$path/$file'></div>";
$i++;
}
}
closedir($dh);
?>
</div>
<input type="submit" value="Usun zaznaczone formularze">
</form>
Now, here's my delete.php
file: 现在,这是我的
delete.php
文件:
<?php
$path = ".";
$dh = opendir($path);
$i=1;
$deletepath = glob('deleteform');
while (($file = readdir($dh)) !== false) {
unlink($deletepath);
$i++;
}
?>
I keep this error: 我保留此错误:
Warning: unlink() expects parameter 1 to be a valid path, array given
警告:unlink()期望参数1为有效路径,给定数组
I'm quite green with PHP, so I decided to ask you guys - how may I make this work? 我对PHP非常了解,所以我决定问大家-我该如何做? Should i
unserialize()
it and add [0]
, [1]
counters? 我应该
unserialize()
并添加[0]
和[1]
计数器吗?
To delete all itens in a folder user this: 要删除文件夹用户中的所有iten,请执行以下操作:
$directory = "folder/";
if ($cat_handle = opendir($directory)) {
while (false !== ($entry = readdir($cat_handle))) {
@unlink($directory.$entry);
}
closedir($cat_handle);
}
You need delete itens or folder? 您需要删除itens或文件夹吗? if you need delete specific item:
如果您需要删除特定项目:
$file_name = "fulano.jpg";
if ($handle = opendir('folder/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if($entry == $file_name){
@unlink('folder/'.$name);
}
}
}
closedir($handle);
}
I believe it works no seu caso, change to accept array now. 我相信它不起作用,请立即更改为接受数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.