Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,025

HOME > PHP > PHP Forum > มีวิธีการ copy file ทั้ง folder ด้วย php ไหมครับ ปกติเวลาจะ copy file ก็จะใช้คำสั่ง copy(file_tmp,path) มันจะมาไฟล์เดียว



 

มีวิธีการ copy file ทั้ง folder ด้วย php ไหมครับ ปกติเวลาจะ copy file ก็จะใช้คำสั่ง copy(file_tmp,path) มันจะมาไฟล์เดียว

 



Topic : 025130



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์




ปกติเวลาจะ copy file ก็จะใช้คำสั่ง copy(file_tmp,path) มันจะมาไฟล์เดียว

แต่ทีนี้ต้องการจะให้มัน copy file ทั้งหมดใน folder เลย จะต้องเขียนคำสั่งยังไงครับ

เป็นการเลือก path จากเครื่อง Client ---> Server php

แบบการเลือก file โดยใช้ <input type=file>



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-03-03 14:42:13 By : naiboimuoun View : 55979 Reply : 9
 

 

No. 1



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<?php
function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false) 
{ 
    // A function to copy files from one directory to another one, including subdirectories and 
    // nonexisting or newer files. Function returns number of files copied. 
    // This function is PHP implementation of Windows xcopy  A:\dir1\* B:\dir2 /D /E /F /H /R /Y 
    // Syntaxis: [$returnstring =] dircopy($sourcedirectory, $destinationdirectory [, $offset] [, $verbose]); 
    // Example: $num = dircopy('A:\dir1', 'B:\dir2', 1); 

    // Original by SkyEye.  Remake by AngelKiha. 
    // Linux compatibility by marajax. 
    // ([danbrown AT php DOT net): *NIX-compatibility noted by Belandi.] 
    // Offset count added for the possibilty that it somehow miscounts your files.  This is NOT required. 
    // Remake returns an explodable string with comma differentiables, in the order of: 
    // Number copied files, Number of files which failed to copy, Total size (in bytes) of the copied files, 
    // and the files which fail to copy.  Example: 5,2,150000,\SOMEPATH\SOMEFILE.EXT|\SOMEPATH\SOMEOTHERFILE.EXT 
    // If you feel adventurous, or have an error reporting system that can log the failed copy files, they can be 
    // exploded using the | differentiable, after exploding the result string. 
    // 
    if(!isset($offset)) $offset=0; 
    $num = 0; 
    $fail = 0; 
    $sizetotal = 0; 
    $fifail = ''; 
    if(!is_dir($dstdir)) mkdir($dstdir); 
    if($curdir = opendir($srcdir)) { 
        while($file = readdir($curdir)) { 
            if($file != '.' && $file != '..') { 
//                $srcfile = $srcdir . '\\' . $file;    # deleted by marajax 
//                $dstfile = $dstdir . '\\' . $file;    # deleted by marajax 
                $srcfile = $srcdir . '/' . $file;    # added by marajax 
                $dstfile = $dstdir . '/' . $file;    # added by marajax 
                if(is_file($srcfile)) { 
                    if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; 
                    if($ow > 0) { 
                        if($verbose) echo "Copying '$srcfile' to '$dstfile'...<br />"; 
                        if(copy($srcfile, $dstfile)) { 
                            touch($dstfile, filemtime($srcfile)); $num++; 
                            chmod($dstfile, 0777);    # added by marajax 
                            $sizetotal = ($sizetotal + filesize($dstfile)); 
                            if($verbose) echo "OK\n"; 
                        } 
                        else { 
                            echo "Error: File '$srcfile' could not be copied!<br />\n"; 
                            $fail++; 
                            $fifail = $fifail.$srcfile.'|'; 
                        } 
                    } 
                } 
                else if(is_dir($srcfile)) { 
                    $res = explode(',',$ret); 
//                    $ret = dircopy($srcfile, $dstfile, $verbose); # deleted by patrick 
                    $ret = dir_copy($srcfile, $dstfile, $verbose); # added by patrick 
                    $mod = explode(',',$ret); 
                    $imp = array($res[0] + $mod[0],$mod[1] + $res[1],$mod[2] + $res[2],$mod[3].$res[3]); 
                    $ret = implode(',',$imp); 
                } 
            } 
        } 
        closedir($curdir); 
    } 
    $red = explode(',',$ret); 
    $ret = ($num + $red[0]).','.(($fail-$offset) + $red[1]).','.($sizetotal + $red[2]).','.$fifail.$red[3]; 
    return $ret; 
} 

?>


พอดีผมไปเจอมา ลองเอาไปประยุกต์ใช้ดูนะครับ






Date : 2009-03-03 15:34:18 By : aprodise
 


 

No. 2



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์


โค้ดที่ให้มา copy ได้เฉพาะที่ folder อยู่บน server ครับ

แต่ถ้า user เป็นคน upload เข้า server จะเขียนโค้ดยังไงครับ
Date : 2009-03-03 17:05:48 By : naiboimuoun
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
โค้ดที่ให้มา copy ได้เฉพาะที่ folder อยู่บน server ครับ

แต่ถ้า user เป็นคน upload เข้า server จะเขียนโค้ดยังไงครับ


จะต้องเลือกอัพโหลดทีล่ะไฟล์ครับ ไม่สามารถทำการอัพโหลดได้ทั้งโฟเดอร์ครับ
Date : 2009-03-03 23:02:49 By : webmaster
 


 

No. 4



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์


ปัญหาคือ เวลา client จะ Update รูปภาพ ครับ ไม่อยากให้ต้องมาใส่ทีละรูป เพราะบางทีมีเป็นร้อยรูป เลยอยากให้ เลือกจาก path หรือเลือกรูปใดรูปหนึ่งบนเครื่อง client เอง แล้วให้มัน copy ทั้งหมดมาไว้ที่ server โดยทำทีละรูป เพราะต้องการเก็บว่าใคร up อะไร เมื่อไหร่ ลงใน DB ด้วยครับ
Date : 2009-03-05 09:19:53 By : naiboimuoun
 


 

No. 5



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


แล้วถ้ารูปมีเป็น พัน มันจะเจอ memory_limit ไหมหรือว่าจะ timeout ไหมครับ
ลองไปหาโค๊ดสำหรับแตกไฟล์พวก zip rar gz อะไรพวกนี้มาดีกว่า แล้วให้เขา บีบไฟล์ก่อนแล้วค่อย อัพโหลดจริงๆ แล้วผมไม่แน่ใจว่า php มันจะมายุ่งอะไรกับ client ได้มากมายขนาดไหน นอกจากใช้ javascript ได้ชัวร์แต่ก็ไม่เต็มที่เหมือนเดิม รอคำตอบท่านต่อไปแล้วผมจะมาดักเก็บความรู้อิอิ
Date : 2009-03-05 10:37:56 By : plakrim
 


 

No. 6



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

หรือไม่ลองเขียนพวก ActiveX ครับ คล้าย ๆ กับ Spaces ของ MSN ครับ

เหตุผลที่ไม่สามารถโหลดทั้งโฟเดอร์และไม่มี Control ตัวไหนที่ Support อันเนื่องจากเกี่ยวกับความปลอดภับของผู้ใช้ครับ เพราะถ้าอัพโหลดทั้งโฟเดอร์ โอกาสที่ Client จะโดนขโมยพวกไฟล์ก็สูงไปด้วยครับ
Date : 2009-03-05 10:51:32 By : webmaster
 


 

No. 7

Guest


ลองศึกษา swfupload ดูครับ ใช้ได้ http://www.swfupload.org
Date : 2009-09-13 00:11:32 By : Diet
 


 

No. 8



โพสกระทู้ ( 4,692 )
บทความ ( 8 )



สถานะออฟไลน์


เห็น java ในเฟซบุคเลือกอัปได้ครั้งละหลายๆไฟล์
Date : 2009-09-13 01:55:46 By : mr.v
 


 

No. 9

Guest


function copyallfile($src,$dst) {
/*$src = source folder
$dst = distination folder */
$files = glob($src.'*');#get all file names
foreach($files as $file){
if(is_file($file))
$filename = explode('/', $file);
copy($file, $dst.end($filename)); #copy file
echo '<b>Copy</b> '.$file.' <b>to</b> '.$dst.end($filename)."<br>";
}
}
Date : 2019-03-16 22:25:35 By : songsaluang
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีวิธีการ copy file ทั้ง folder ด้วย php ไหมครับ ปกติเวลาจะ copy file ก็จะใช้คำสั่ง copy(file_tmp,path) มันจะมาไฟล์เดียว
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่