A simple example of imitating elFinder and extracting key member methods
The implemented functions are:
Realize multi-file copy or move operations
Note: In order to facilitate testing, some judgments have been simplified. And a new test folder will be generated as the destination folder in the directory where the program file is located. Modification is required if actual use is required.
?<?php /** * 復(fù)制/移動操作簡單示例 : >PHP5 * */ /** * 判斷文件是否存在 * */ function _isFind($filename) { return @file_exists($filename); } /** * 判斷文件夾是否存在? 簡單處理: 僅對根目錄進行判斷 * */ function _isFindDir($dir) { $ls = scandir(dirname(__FILE__)); foreach ($ls as $val) { if ($val == $dir) return TRUE; } return FALSE; } /** * 復(fù)制或移動 * * @param array 源文件夾數(shù)組: 簡單處理:采用文件名作為元素值 * @param string 目的文件夾 * @param string 操作數(shù): move - 移動 ; copy - 復(fù)制 * @return bool */ function _copy_move($src = array(), $dst = '', $op = 'move') { if ( ! is_array($src)) { $src = array($src); } //判斷源文件是否存在? foreach ($src as $val) { if ( _isFind($val) === FALSE) { return _log('Src file not find', $val); } } //判斷目的文件夾是否存在? 如果不存在就生成 //簡單處理: 實際應(yīng)用需要修改 if (_isFindDir($dst) === FALSE) { @mkdir($dst); } //執(zhí)行移動或復(fù)制操作 foreach ($src as $val) { $_dst = $dst.'/'.basename($val); //判斷目的文件是否存在? 存在不允許進行操作 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!'; } /** * 復(fù)制操作 * */ 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.'/'.$ls[$i]; $_dst = $dst.'/'.$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; } /** * 日志記錄 * */ 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); } /** * 示例 * 1. 需要修改$src的數(shù)組參數(shù) ; 2. 可以修改_copy_move的第三個參數(shù)以分別測試move/copy操作 * */ $src = array('img', 'min', 'phpinfo.php'); $dst = 'test'; var_dump(_copy_move($src, $dst, 'copy')); /*end of php*/

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
