|
 |
|
การจัดการย้ายข้อมูลเวลาเปลี่ยน parth ควรทำอย่างไรดีครับ |
|
 |
|
|
 |
 |
|
คือผมมี การสร้าง type เอกสาร เก็บ id name url
แล้วเมื่อเวลาเปลี่ยน url ก็ต้องเปลี่ยน ที่เก็บไฟล์ ตามไปด้วย อยากทราบว่า โคด ผมได้บ้างไม่ได้บ้างอะครับควรแก้ตรงใหนดีครับ
Code (PHP)
if($_POST["act"]=='Edit'){
$t4 = $_POST['t4']; //name
$t5 = $_POST['t5']; // url
select parth
$sql = "select * from doctype WHERE type_id = ' ".$_POST['ide']." ' ";
$sql = mysql_query ($sql);
$sql = mysql_fetch_array($sql);
$parth = $sql['type_parth'];
//check old folder
if (file_exists($t5)) {}
else { $flgCreate = mkdir($t5);}
$files = glob($parth.'*');
foreach($files as $file)
{
$Str_file = explode("/",$file);
$name = end($Str_file);
//movefile
rename($file,$t5.$name);
}
$sql = "UPDATE doctype SET type_name='$t4' ,type_parth='$t5' WHERE type_id = ' ".$_POST['ide']." ' ";
$precon = mysql_query($sql);
// log
$t1 = $_POST['ide'];
$t1 = 'id '.$t1;
$datel = date("Y:m:d");
$timel =date("H:i:s");
$name = $_SESSION['User_Loginnew']['user_name'];
$actt = "EDIT TYPENAME";
$datet = date("Y-m-d").' '.date("H:i:s");
$pc="INSERT INTO logdb(log_name,log_date,log_time,log_file,log_act) VALUES ('$name','$datel','$timel','$t1','$actt')";
$precon2 = mysql_query($pc);
//end log
if(!$precon){
echo '<script type="text/javascript">
alert("EDIT ERROR");
</script>';
}else{
header('Location:MANAGEMENTTYPE .php');
}
}
Tag : PHP, Ms Access

|
|
 |
 |
 |
 |
Date :
2014-09-17 08:04:00 |
By :
summawat |
View :
731 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หรือจะ เอาแบบนี้ได้ไหมครับ
Code (PHP)
//check old folder
if (file_exists($t5)) {}
else { $flgCreate = mkdir($t5);}
$files = glob($parth.'*');
foreach($files as $file)
{
$Str_file = explode("/",$file);
$name = end($Str_file);
//movefile
//rename($file,$t5.$name);
move_uploaded_file($_FILES[$flie]["tmp_name"],$t5.$name);
unlink($parth."/".$name);
}
|
ประวัติการแก้ไข 2014-09-17 09:02:20 2014-09-17 09:02:21
 |
 |
 |
 |
Date :
2014-09-17 08:45:50 |
By :
summawat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่เข้าใจคอนเซ็ปเท่าไหร่ 
|
 |
 |
 |
 |
Date :
2014-09-17 09:12:56 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลาเราเก็บข้อมูลอะครับ เก็บ เอกสารไว้ใน ไดเรคทอรี่
แต่ เราจะย้าย ข้อมูลอะครับ
เราต้องย้ายไปใน ไดเรคทอรี่ใหม่ แล้วลบไฟล์และไดเรคทอรี่อันเก่าทิ้งอะครับ ซึ่งให้ชื่อไฟล์เหมือนเดิมแต่เปลี่ยนไดเรคทอรี่ใหม่เท่านั้น
ควรจะเขียนโคดแบบใหนดีครับ

|
ประวัติการแก้ไข 2014-09-17 09:43:05 2014-09-17 09:44:15
 |
 |
 |
 |
Date :
2014-09-17 09:41:34 |
By :
summawat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ จาก โคดข้าง บนสุด มันใช้ได้ครับ
fileupload/ISK/
แบบนี้ไม่ error
ถ้าเราลืมใส่
fileupload/ISK
ข้างหลังสุดมัน จะ error ครับโดย จะไปรีเนมไฟล์ แล้วย้ายแทนอะครับอะไรประมาณนี้
|
 |
 |
 |
 |
Date :
2014-09-17 10:40:21 |
By :
summawat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองแก้โคดได้อย่างนี้ครับ
Code (PHP)
//check old folder
if (file_exists($t5)) {}
else { $flgCreate = mkdir($t5);}
$rest = substr($t5, -1); //check last word new edit/
if ($rest != "/") {$t5 =$t5."/"; }
$files = glob($parth.'*');
foreach($files as $file)
{
$Str_file = explode("/",$file);
$name = end($Str_file);
//movefile
rename($file,$t5.$name);
}
|
 |
 |
 |
 |
Date :
2014-09-17 11:10:16 |
By :
summawat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|