|
 |
|
เรียกไฟล์จากFOLDER มาแล้ว ผมอย่ากจะแชกข้อความ DEL เข้าไปด้วยอะครับ |
|
 |
|
|
 |
 |
|
สรุปแล้วจะลบใช่ไหม่ครับ ???
public function deleteFile($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file)){
echo $file.' Deleted...';
unlink($dirname."/".$file);
}
else
$this->deleteFile($dirname.'/'.$file);
}
}
closedir($dir_handle);
return true;
}
|
 |
 |
 |
 |
Date :
2011-06-14 15:48:43 |
By :
t-monroe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับผล แต่ผม อย่ากให้มันเลือก ลบได้อะครับ ทีละไฟล์ ครับ
ขอบคุนนะครับที่มาตอบให้อะครับ
|
 |
 |
 |
 |
Date :
2011-06-14 16:21:52 |
By :
ลูnLต่า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วันนี้ก็มาถึงครับ ทำได้แล้ว
code หน้า อัพไฟล์
Code (PHP)
<html>
<head>
<title></title>
<script language="javascript">
function fncCreateElement(){
var mySpan = document.getElementById('mySpan');
var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"file");
myElement1.setAttribute('name',"filUpload[]");
//myElement1.setAttribute('id',"filUpload[]");
mySpan.appendChild(myElement1);
//*** Remove Element ***//
/*
var deleteEle = document.getElementById('txt1');
mySpan.removeChild(deleteEle);
*/
var myElement2 = document.createElement('<br>');
mySpan.appendChild(myElement2);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<form name="frmMain" method="post" action="up.php" enctype="multipart/form-data">
<input type="file" name="filUpload[]">
<input name="btnButton" id="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"><Next>
<br>
<span id="mySpan"></span>
<form name="form1" method="post" action="v.php" enctype="multipart/form-data">
<label></label>
<label></label>
<label></label>
<input name="btnSubmit" type="submit" value="Up">
Code (PHP)
[php]<html>
<head>
<title></title>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<?
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"files/".$_FILES["filUpload"]["name"][$i]))
{
echo "เพิ่มภาพเรียบร้อยแล้ว/แสดงภาพ<br>";
}
}
}
/*
?>
<?php
$filename="image.jpg";
$extension=explode(".",$filename);
echo $extension[1];
?>
*/
$im="ที่อยู่ของไฟล์หรือรุปภาพ";
if(file_exists($im)){
$chkimage=@getimagesize($im);
if($chkimage[2]==1){
echo"แสดงภาพที่มีนามสกุล .GIF";
}elseif($chkimage[2]==2){
echo"แสดงภาพที่มีนามสกุล .JPG";
}
}
?>
<a href ='v.php'>filename</a>
</body>
</html>
<label></label>
</form>
</body>
</html>
หน้าแสดงผล
Code (PHP)
<body>
<p>
<?
$objOpen = opendir("files");
while (($file = readdir($objOpen)) !== false)
{
echo " <a href ='dell.php?name=$file'>DELELEFile</a>" . $file ."<br />";//สร้างตัวส่งค่าไปยัง From ลบ ในที่นี้กำหนดค่าเป็นให้ส่ง 'name=$file' โดยใช้ฟังชัน_getในการส่งค่าตัวแปล name
}
?>
<form name="form1" method="post" action="">
<label>
</body>
[/php]
หน้าลบCode (PHP)
<?php
$files=$_GET['name']; // อันนี้เป็นการ get ค่าที่ส่งมานะครับ ซึ่งผมใช้เป็นตัว สร้าง ชื่อ file นะครับ
echo $files;//เป็นการประกาศค่าที่รับมา ว่ารับค่าอะไร ก่อนที่จะลบไฟล์
///จัดการลบข้อมูลในdatabase
include"v.php";
$strSQL = "DELETE FROM files WHEREf FilesName='$filesname'";
$del=("./files/$name");// ตรงนี้เป็น part ที่ให้เข้าไป ลบ file ครับ
@unlink("$del");
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Record Deleted.";
}
?>
|
ประวัติการแก้ไข 2011-06-15 12:12:27
 |
 |
 |
 |
Date :
2011-06-15 10:31:38 |
By :
ลูnLต่า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอขอบคุณไปยัง code หลายอันที่ผมได้ไปนำมาผสมกันมั่วจนจำไม่ได้ว่ามีขอใคร บ้าง แต่ผมก็สามารถทำจน RUN ได้
ขอบคุนมากๆครับ
|
 |
 |
 |
 |
Date :
2011-06-15 10:35:10 |
By :
ลูnLต่า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โทดครับ ขี้ลืมจังเลยผม
มันยังเป็นภาษาต่างดาวอยุ่เลยครับ
ช่วยแนะนำด้วยผมหน่อยครับ
|
 |
 |
 |
 |
Date :
2011-06-15 10:38:09 |
By :
ลูnLต่า |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|