[英]PHP/HTML - issue with form handling - unlink() warning
我試圖允許用戶通過html form
和PHP
從服務器上的文件夾中delete images
。
這是我的html
表單標記以及PHP腳本從前面提到的文件夾中生成列表images
。 我添加了帶有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>
現在,這是我的delete.php
文件:
<?php
$path = ".";
$dh = opendir($path);
$i=1;
$deletepath = glob('deleteform');
while (($file = readdir($dh)) !== false) {
unlink($deletepath);
$i++;
}
?>
我保留此錯誤:
警告:unlink()期望參數1為有效路徑,給定數組
我對PHP非常了解,所以我決定問大家-我該如何做? 我應該unserialize()
並添加[0]
和[1]
計數器嗎?
要刪除文件夾用戶中的所有iten,請執行以下操作:
$directory = "folder/";
if ($cat_handle = opendir($directory)) {
while (false !== ($entry = readdir($cat_handle))) {
@unlink($directory.$entry);
}
closedir($cat_handle);
}
您需要刪除itens或文件夾嗎? 如果您需要刪除特定項目:
$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);
}
我相信它不起作用,請立即更改為接受數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.