This article describes how to copy a mobile file in php. The example shows how to copy and move a file in php. For more information, see
This article describes how to copy a mobile file in php. The example shows how to copy and move a file in php. For more information, see
This example describes how to copy a mobile file in php. Share it with you for your reference. The details are as follows:
A simple example of the key member Method Used for copying elFinder
Functions:
Multi-file copy or move operations
Note: In order to facilitate the test, some judgments are processed simply. In the directory where the program file is located
Generate a new test folder as the destination folder. If it needs to be modified.
The copy. php file is as follows:
Signature <? Php/*** simple example of copy/Move operations:> PHP5 *** // *** determines whether the file exists **/function _ isFind ($ filename) {return @ file_exists ($ filename);}/*** determines whether a folder exists? Simple processing: only judge the root directory **/function _ isFindDir ($ dir) {$ ls = scandir (dirname (_ FILE __)); foreach ($ ls as $ val) {if ($ val = $ dir) return TRUE;} return FALSE ;} /*** copy or move ** @ param array source folder array: simple processing: the object name is used as the element value * @ param string destination folder * @ param string operand: move-move; copy-copy * @ return bool */function _ copy_move ($ src = array (), $ dst = '', $ op = 'move ') {if (! Is_array ($ src) {$ src = array ($ src);} // determines whether the source file exists? Foreach ($ src as $ val) {if (_ isFind ($ val) === FALSE) {return _ log ('src file not find ', $ val );}} // determine whether the destination folder exists? If it does not exist, generate // simple processing: the actual application needs to modify if (_ isFindDir ($ dst) === FALSE) {@ mkdir ($ dst );} // execute the move or copy operation foreach ($ src as $ val) {$ _ dst = $ dst.' http://www.jb51.net/ '. Basename ($ val); // determines whether the target file exists? If (_ isFind ($ _ dst) === TRUE) {return _ log ('dst file is exists', $ Dst );} else if (strpos ($ dst, $ val) == 0) {return _ log ('unable to copy/move into itself ');} if (strtolower ($ op) === 'move ') {if (! Rename ($ val, $ _ dst) {return _ log ('unable to move files', $ val) ;}} else if (strtolower ($ op) === 'copy') {if (! _ Copy ($ val, $ _ dst) {return _ log ('unable to copy files', $ val) ;}} return 'success! ';}/*** Copy operation **/function _ copy ($ src, $ dst) {if (! Is_dir ($ src) {if (! Copy ($ src, $ dst) {return _ log ('unable to copy files', $ src) ;}} else {mkdir ($ dst ); $ ls = scandir ($ src); for ($ I = 0; $ I <count ($ ls); $ I ++) {if ($ ls [$ I] = '. 'OR $ ls [$ I] = '.. ') continue; $ _ src = $ src.' http://www.jb51.net/ '. $ Ls [$ I]; $ _ dst = $ dst .' http://www.jb51.net/ '. $ Ls [$ I]; if (is_dir ($ _ src) {if (! _ Copy ($ _ src, $ _ dst) {return _ log ('unable to copy files', $ _ src) ;}} else {if (! Copy ($ _ src, $ _ dst) {return _ log ('unable to copy files', $ _ src) ;}}} return TRUE ;} /*** log record **/function _ log ($ msg, $ arg = '') {if ($ arg! = '') {$ Msg =" date [". date ('Y-m-d H: I: s '). "] \ tmsg [". $ msg. "] \ targ [". $ arg. "] \ n";} else {$ msg = "date [". date ('Y-m-d H: I: s '). "] \ tmsg [". $ msg. "] \ n";} echo $ msg; return @ file_put_contents ('Copy. log', $ msg, FILE_APPEND);}/*** example * 1. the array parameter of $ src needs to be modified; 2. you can modify the third parameter of _ copy_move to test the move/copy operation respectively **/$ src = array ('img ', 'Min', 'phpinfo. php '); $ dst = 'test'; var_dump (_ copy_move ($ src, $ dst, 'copy');/* end of php */
I hope this article will help you with php programming.