ลบไฟล์ได้ แต่ยังขึ้น Error อยู่ ช่วยดู Code ทีคะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ลบไฟล์ได้ แต่ยังขึ้น Error อยู่ ช่วยดู Code ทีคะ
ลบไฟล์ได้ แต่ยังขึ้น Error อยู่ ช่วยดู Code ทีคะ
ต้องการลบทีละรูปภาพคะ แต่พอกดลบแล้ว ยังขึ้น Error อยู่ ข้อความว่า
Warning: readdir(): 4 is not a valid Directory resource in C:xampplitehtdocs....DeleteFiles.php on line 11
งงคะ readdir(): 4 หมายความว่ายังไงคะ :eek:
DeleteFiles.php
<?php
include("config.php");
$dir = "files";
$opendir =opendir($dir);
while ($file = readdir($opendir)) {
if($file != '..' && $file !='.' && $file !=''){
if (!is_dir($file)){
unlink($dir . "/" . $file);
}
closedir($opendir);
clearstatcache();
}
}
?>
config.php
<?php
//path where to store images
$dir = "files/";
//check if folders are Writable or not
//please CHOMD them 777
if (!is_writeable($dir)){
die ("Error: The directory <b>($dir)</b> is NOT writable");
}
?>
รบกวนดูให้ทีจร้า ไม่รู้ว่าผิดตรงไหน งงมากๆเลย T_T
ขอบคุงล่วงหน้ามากกกๆๆค่ะ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ให้ดูที่สั่ง closedir ต้องอยู่ข้างนอกการวน ลูป เพราะถ้าอยู่ข้างในนั้น เพราะถ้าอยู่ด้านในมันก็จะปิด ก่อนที่เราจะทำการ readdir จนครบ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php include ( "config.php" ); $dir = "files" ; $opendir =opendir( $dir ); while ( $file = readdir( $opendir )) { if ( $file != '..' && $file != '.' && $file != '' ){ if (! is_dir ( $file )){ unlink( $dir . "/" . $file ); } } } closedir ( $opendir ); clearstatcache(); ?> |

ความคิดเห็นที่
2
ได้แล้วคะ ไม่ Error แต่กลายเป็นว่า ลบไฟล์ภาพไปทั้งหมดเลยอะคะ T-T

ขอบคุณทุกการสนับสนุน
![]()