function copyFolder($src, $dst) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { copyFolder($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); }
function copyFolder($from_dir, $to_dir) { if (!is_dir($from_dir)) { return false; } $from_files = scandir($from_dir); if (!file_exists($to_dir)) { mkdir($to_dir); // @mkdir($to_dir) << 跟這樣差異在哪!? } if (!empty($from_files)) { foreach ($from_files as $file) { if ($file == '.' || $file == '..') { continue; } if (is_dir($from_dir . '/' . $file)) { copyFolder($from_dir . '/' . $file, $to_dir . '/' . $file); } else { copy($from_dir . '/' . $file, $to_dir . '/' . $file); } } } return true; }
/** * Create a EditedEmbed object. * * @return void */ public function create() { $this->auth->restrict($this->permissionCreate); // if (isset($_POST['save'])) { // if ($insert_id = $this->save_editedembed()) { // log_activity($this->auth->user_id(), lang('editedembed_act_create_record') . ': ' . $insert_id . ' : ' . $this->input->ip_address(), 'editedembed'); // Template::set_message(lang('editedembed_create_success'), 'success'); // redirect(SITE_AREA . '/embeds/editedembed'); // } // // Not validation error // if ( ! empty($this->editedembed_model->error)) { // Template::set_message(lang('editedembed_create_failure') . $this->editedembed_model->error, 'error'); // } // } $historyID = $this->uri->segment(5); $history = $this->history_model->find($historyID); $embed = $this->embedcontent_model->find($history->embedid); //$editembedgoodies=array('history'=>$history, // 'embed'=>$embed); if ($embed) { //echo 'Found it '.$embed->name ; //printf("uniqid('', true): %s\r\n", uniqid('".$embed->id.$embed->name."', true)); //insert new editedembed $uniqueName = uniqid($embed->id . '_', true); $editedEmbedData['count'] = 1; $editedEmbedData['embedid'] = $embed->id; $editedEmbedData['name'] = $uniqueName; $editedEmbedData['sourceurl'] = $embed->sourceurl; $neweditedEmbedID = $this->editedembed_model->insert($editedEmbedData); $array = array('id' => $embed->id); $embedData = $this->embedcontent_model->where($array)->find_all(); $embedFileName = $embedData[0]->name; mkdir(config_item('smartembed_static_site_location') . $uniqueName, 0755); copyFolder(config_item('smartembed_static_site_location') . $embedFileName, config_item('smartembed_static_site_location') . $uniqueName); $this->session->set_userdata('editedembedID', $neweditedEmbedID); $this->session->set_userdata('embedname', $uniqueName); redirect(SITE_AREA . '/embeds/history/edit/' . $historyID); // $_POST['historyID']=$historyID; // $_POST['neweditedembedID']=$neweditedembedID; //redirect(SITE_AREA . '/embeds/history/'); // $this->history_model->update($id, $data); // print_r($this->history_model->find($historyID)); //$returnID =$this->history_model->insert($historyData); //print_r($historyData); //echo 'New Embed ID '.$neweditedembedid.' history '.$historyID.' - '.$returnID; } // else{ // echo 'Go again'; // } //Template::set('goodies', $editembedgoodies); //Template::set('toolbar_title', lang('editedembed_action_create')); //Template::render(); }
<?php require_once '../dir.func.php'; require_once '../file.func.php'; require_once '../common.func.php'; //目标目录 $mubiaopath = "../" . $_POST['mubiaopath']; //原路径 $sourcepath = $_POST['path']; //文件名 $folderp = $_REQUEST['folderp']; $filep = $_REQUEST['filep']; $folderp1 = explode(",", $folderp); $filep1 = explode(",", $filep); for ($i = 0; $i < count($folderp1); $i++) { copyFolder("../" . $folderp1[$i], $mubiaopath . "/" . basename("../" . $folderp1[$i])); } for ($i1 = 0; $i1 < count($filep1); $i1++) { copyFile("../" . $filep1[$i1], $mubiaopath); } echo "<script>parent.location.href='../file_gl.php?path=" . $sourcepath . "&info=操作成功'</script>";
//echo $newname,"-",$dirname,"-",$path; $mes = renameFolder($dirname, $path . "/" . $newname); alertMes($mes, $redirect); } elseif ($act == "copyFolder") { $str = <<<EOF \t<form action="index.php?act=doCopyFolder" method="post"> \t将文件夹复制到:<input type="text" name="dstname" placeholder="将文件夹复制到"/> \t<input type="hidden" name="path" value="{$path}" /> \t<input type='hidden' name='dirname' value='{$dirname}' /> \t<input type="submit" value="复制文件夹"/> \t</form> EOF; echo $str; } elseif ($act == "doCopyFolder") { $dstname = $_REQUEST['dstname']; $mes = copyFolder($dirname, $path . "/" . $dstname . "/" . basename($dirname)); alertMes($mes, $redirect); } elseif ($act == "cutFolder") { $str = <<<EOF \t<form action="index.php?act=doCutFolder" method="post"> \t将文件夹剪切到:<input type="text" name="dstname" placeholder="将文件剪切到"/> \t<input type="hidden" name="path" value="{$path}" /> \t<input type='hidden' name='dirname' value='{$dirname}' /> \t<input type="submit" value="剪切文件夹"/> \t</form> EOF; echo $str; } elseif ($act == "doCutFolder") { //echo "文件夹被剪切了"; $dstname = $_REQUEST['dstname']; $mes = cutFolder($dirname, $path . "/" . $dstname);
function copyFolder($folder, $dir_destin, $dir_source) { global $conn_id; global $serverTmp; global $lang_folder_cant_access; global $lang_folder_exists; global $lang_folder_cant_chmod; global $lang_folder_cant_make; global $lang_server_error_down; global $lang_file_cant_chmod; global $lang_chmod_no_support; $isError = 0; // Check if ftp_chmod() exists if (!function_exists('ftp_chmod')) { $_SESSION["errors"][] = $lang_chmod_no_support; } // Check source folder exists if (!@ftp_chdir($conn_id, $dir_source . "/" . $folder)) { if (checkFirstCharTilde($dir_source) == 1) { if (!@ftp_chdir($conn_id, replaceTilde($dir_source) . "/" . $folder)) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_access); $isError = 1; } } else { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_access); $isError = 1; } } if ($isError == 0) { // Check if destination folder exists if (checkFileExists("d", $folder, $dir_destin) == 1) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_exists); } else { // Create the new folder if (!@ftp_mkdir($conn_id, $dir_destin . "/" . $folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_mkdir($conn_id, replaceTilde($dir_destin) . "/" . $folder)) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_make); $isError = 1; } } else { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_make); $isError = 1; } } } } if ($isError == 0) { // Copy permissions (Lin) if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") { $mode = getPerms($dir_source, $folder); $lang_folder_cant_chmod = str_replace("[perms]", $mode, $lang_folder_cant_chmod); if (function_exists('ftp_chmod')) { if (!@ftp_chmod($conn_id, $mode, $dir_destin . "/" . $folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($dir_destin) . "/" . $folder)) { recordFileError("folder", $folder, $lang_folder_cant_chmod); } } else { recordFileError("folder", $folder, $lang_folder_cant_chmod); } } } } // Go through array of files/folders $ftp_rawlist = getFtpRawList($dir_source . "/" . $folder); if (is_array($ftp_rawlist)) { $count = 0; foreach ($ftp_rawlist as $ff) { $count++; $isDir = 0; $isError = 0; // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Mac) // skip first line if ($_SESSION["win_lin"] == "mac") { if ($count == 1) { continue; } $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\\s]+/", $ff, 4); $size = $ff[2]; $file = $ff[3]; if ($size == "<DIR>") { $isDir = 1; } } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if (getFileType($perms) == "d") { copyFolder($file, $dir_destin . "/" . $folder, $dir_source . "/" . $folder); } else { $fp1 = tempnam($serverTmp, "monsta-"); $fp2 = $dir_source . "/" . $folder . "/" . $file; $fp3 = $dir_destin . "/" . $folder . "/" . $file; register_shutdown_function('shutdown_unlinkTempFile', $fp1); ensureFtpConnActive(); // Download if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_get($conn_id, $fp1, replaceTilde($fp2), FTP_BINARY)) { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } else { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } // Upload if ($isError == 0) { ensureFtpConnActive(); if (!@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp3), $fp1, FTP_BINARY)) { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } else { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } } if ($isError == 0) { // Chmod files (Lin) if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") { $perms = getChmodNumber($perms); $mode = formatChmodNumber($perms); $lang_file_cant_chmod = str_replace("[perms]", $perms, $lang_file_cant_chmod); if (function_exists('ftp_chmod')) { if (!@ftp_chmod($conn_id, $mode, $fp3)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($fp3))) { recordFileError("file", $file, $lang_server_error_down); } } else { recordFileError("file", $file, $lang_server_error_down); } } } } } // Delete tmp file unlink($fp1); } } } } } }
function copyHtmlToWeb() { $webDir = ''; $toWebDir = ''; $toFilePath = ''; $filePath = ''; $fileName = ''; $fileList = ''; $splStr = ''; $content = ''; $s = ''; $s1 = ''; $c = ''; $webImages = ''; $webCss = ''; $webJs = ''; $splJs = ''; $webFolderName = ''; $jsFileList = ''; $setFileCode = ''; $nErrLevel = ''; $jsFilePath = ''; $url = ''; $setFileCode = @$_REQUEST['setcode']; //设置文件保存编码 handlePower('复制生成HTML页面'); //管理权限处理 writeSystemLog('', '复制生成HTML页面'); //系统日志 $webFolderName = $GLOBALS['cfg_webTemplate']; if (left($webFolderName, 1) == '/') { $webFolderName = mid($webFolderName, 2, -1); } if (right($webFolderName, 1) == '/') { $webFolderName = mid($webFolderName, 1, len($webFolderName) - 1); } if (inStr($webFolderName, '/') > 0) { $webFolderName = mid($webFolderName, inStr($webFolderName, '/') + 1, -1); } $webDir = '/htmladmin/' . $webFolderName . '/'; $toWebDir = '/htmlw' . 'eb/viewweb/'; CreateDirFolder($toWebDir); $toWebDir = $toWebDir . pinYin2($webFolderName) . '/'; deleteFolder($toWebDir); //删除 CreateFolder('/htmlweb/web'); //创建文件夹 防止web文件夹不存在20160504 deleteFolder($webDir); CreateDirFolder($webDir); $webImages = $webDir . 'Images/'; $webCss = $webDir . 'Css/'; $webJs = $webDir . 'Js/'; copyFolder($GLOBALS['cfg_webImages'], $webImages); copyFolder($GLOBALS['cfg_webCss'], $webCss); CreateFolder($webJs); //创建Js文件夹 //处理Js文件夹 $splJs = aspSplit(getDirJsList($webJs), vbCrlf()); foreach ($splJs as $key => $filePath) { if ($filePath != '') { $toFilePath = $webJs . getFileName($filePath); aspEcho('js', $filePath); moveFile($filePath, $toFilePath); } } //处理Css文件夹 $splStr = aspSplit(getDirCssList($webCss), vbCrlf()); foreach ($splStr as $key => $filePath) { if ($filePath != '') { $content = getFText($filePath); $content = replace($content, $GLOBALS['cfg_webImages'], '../images/'); $content = deleteCssNote($content); $content = PHPTrim($content); //设置为utf-8编码 20160527 if (lCase($setFileCode) == 'utf-8') { $content = replace($content, 'gb2312', 'utf-8'); } WriteToFile($filePath, $content, $setFileCode); aspEcho('css', $GLOBALS['cfg_webImages']); } } //复制栏目HTML $GLOBALS['isMakeHtml'] = true; $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'webcolumn where isonhtml=true'); while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) { $GLOBALS['glb_filePath'] = replace(getColumnUrl($rss['columnname'], 'name'), $GLOBALS['cfg_webSiteUrl'] . '/', ''); if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') { $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html'; } if (right($GLOBALS['glb_filePath'], 5) == '.html') { if (right($GLOBALS['glb_filePath'], 11) == '/index.html') { $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf(); } else { $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList; } $fileName = replace($GLOBALS['glb_filePath'], '/', '_'); $toFilePath = $webDir . $fileName; copyFile($GLOBALS['glb_filePath'], $toFilePath); aspEcho('导航', $GLOBALS['glb_filePath']); } } //复制文章HTML $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'articledetail where isonhtml=true'); while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) { $GLOBALS['glb_url'] = getHandleRsUrl($rss['filename'], $rss['customaurl'], '/detail/detail' . $rss['id']); $GLOBALS['glb_filePath'] = replace($GLOBALS['glb_url'], $GLOBALS['cfg_webSiteUrl'] . '/', ''); if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') { $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html'; } if (right($GLOBALS['glb_filePath'], 5) == '.html') { if (right($GLOBALS['glb_filePath'], 11) == '/index.html') { $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf(); } else { $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList; } $fileName = replace($GLOBALS['glb_filePath'], '/', '_'); $toFilePath = $webDir . $fileName; copyFile($GLOBALS['glb_filePath'], $toFilePath); aspEcho('文章' . $rss['title'], $GLOBALS['glb_filePath']); } } //复制单面HTML $rssObj = $GLOBALS['conn']->query('select * from ' . $GLOBALS['db_PREFIX'] . 'onepage where isonhtml=true'); while ($rss = $GLOBALS['conn']->fetch_array($rssObj)) { $GLOBALS['glb_url'] = getHandleRsUrl($rss['filename'], $rss['customaurl'], '/page/page' . $rss['id']); $GLOBALS['glb_filePath'] = replace($GLOBALS['glb_url'], $GLOBALS['cfg_webSiteUrl'] . '/', ''); if (right($GLOBALS['glb_filePath'], 1) == '/' || right($GLOBALS['glb_filePath'], 1) == '') { $GLOBALS['glb_filePath'] = $GLOBALS['glb_filePath'] . 'index.html'; } if (right($GLOBALS['glb_filePath'], 5) == '.html') { if (right($GLOBALS['glb_filePath'], 11) == '/index.html') { $fileList = $fileList . $GLOBALS['glb_filePath'] . vbCrlf(); } else { $fileList = $GLOBALS['glb_filePath'] . vbCrlf() . $fileList; } $fileName = replace($GLOBALS['glb_filePath'], '/', '_'); $toFilePath = $webDir . $fileName; copyFile($GLOBALS['glb_filePath'], $toFilePath); aspEcho('单页' . $rss['title'], $GLOBALS['glb_filePath']); } } //批量处理html文件列表 //call echo(cfg_webSiteUrl,cfg_webTemplate) //call rwend(fileList) $sourceUrl = ''; $replaceUrl = ''; $splStr = aspSplit($fileList, vbCrlf()); foreach ($splStr as $key => $filePath) { if ($filePath != '') { $filePath = $webDir . replace($filePath, '/', '_'); aspEcho('filePath', $filePath); $content = getFText($filePath); foreach ($splStr as $key => $s) { $s1 = $s; if (right($s1, 11) == '/index.html') { $s1 = left($s1, len($s1) - 11) . '/'; } $sourceUrl = $GLOBALS['cfg_webSiteUrl'] . $s1; $replaceUrl = $GLOBALS['cfg_webSiteUrl'] . replace($s, '/', '_'); //Call echo(sourceUrl, replaceUrl) '屏蔽 否则大量显示20160613 $content = replace($content, $sourceUrl, $replaceUrl); } $content = replace($content, $GLOBALS['cfg_webSiteUrl'], ''); //删除网址 $content = replace($content, $GLOBALS['cfg_webTemplate'] . '/', ''); //删除模板路径 记 //content=nullLinkAddDefaultName(content) foreach ($splJs as $key => $s) { if ($s != '') { $fileName = getFileName($s); $content = replace($content, 'Images/' . $fileName, 'js/' . $fileName); } } if (inStr($content, '/Jquery/Jquery.Min.js') > 0) { $content = replace($content, '/Jquery/Jquery.Min.js', 'js/Jquery.Min.js'); copyFile('/Jquery/Jquery.Min.js', $webJs . '/Jquery.Min.js'); } $content = replace($content, '<a href="" ', '<a href="index.html" '); //让首页加index.html createFileGBK($filePath, $content); } } //把复制网站夹下的images/文件夹下的js移到js/文件夹下 20160315 $htmlFileList = ''; $splHtmlFile = ''; $splJsFile = ''; $htmlFilePath = ''; $jsFileName = ''; $jsFileList = getDirJsNameList($webImages); $htmlFileList = getDirHtmlList($webDir); $splHtmlFile = aspSplit($htmlFileList, vbCrlf()); $splJsFile = aspSplit($jsFileList, vbCrlf()); foreach ($splHtmlFile as $key => $htmlFilePath) { $content = getFText($htmlFilePath); foreach ($splJsFile as $key => $jsFileName) { $content = regExp_Replace($content, 'Images/' . $jsFileName, 'js/' . $jsFileName); } $nErrLevel = 0; $content = handleHtmlFormatting($content, false, $nErrLevel, '|删除空行|'); //|删除空行| $content = handleCloseHtml($content, true, ''); //闭合标签 $nErrLevel = checkHtmlFormatting($content); if (checkHtmlFormatting($content) == false) { echoRed($htmlFilePath . '(格式化错误)', $nErrLevel); //注意 } //设置为utf-8编码 if (lCase($setFileCode) == 'utf-8') { $content = replace($content, '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); } $content = PHPTrim($content); WriteToFile($htmlFilePath, $content, $setFileCode); } //images下js移动到js下 foreach ($splJsFile as $key => $jsFileName) { $jsFilePath = $webImages . $jsFileName; $content = getFText($jsFilePath); $content = PHPTrim($content); WriteToFile($webJs . $jsFileName, $content, $setFileCode); DeleteFile($jsFilePath); } copyFolder($webDir, $toWebDir); //使htmlWeb文件夹用php压缩 if (@$_REQUEST['isMakeZip'] == '1') { makeHtmlWebToZip($webDir); } //使网站用xml打包20160612 if (@$_REQUEST['isMakeXml'] == '1') { makeHtmlWebToXmlZip('/htmladmin/', $webFolderName); } //浏览地址 $url = 'http://10.10.10.57/' . $toWebDir; aspEcho('浏览', '<a href=\'' . $url . '\' target=\'_blank\'>' . $url . '</a>'); }
$str = "\n <form action='index.php?mode=doRenameFolder' method='post'>\n <input type='text' name='path' value='{$path}' />\n <input type='text' name='filename' value='{$filename}' />\n <label>请输入新的文件夹名称:</label>\n <input type='text' name='disFile' >\n <input type='submit' value='确定'>\n </form>\n "; echo $str; } else { if ($mode == 'doRenameFolder') { $src = $filename; $dis = $_REQUEST['disFile']; $msg = renameFolder($src, "file/" . $dis); alertMsg($msg, $url); } elseif ($mode == 'copyFolder') { $str = "\n <form action='index.php?mode=doCopyFolder' method='post'>\n <input type='hidden' name='filename' value='{$filename}' />\n <input type='hidden' name='path' value='{$path}' />\n <label>复制到:</label>\n <input type='text' name='disFile' placeholder='复制到'>\n <input type='submit' value='确定'/>\n </form>"; echo $str; } else { if ($mode == 'doCopyFolder') { $srcFile = $filename; $dis = $_REQUEST['disFile']; $msg = copyFolder($srcFile, 'file' . "/" . $dis); alertMsg($msg, $urlt); } elseif ($mode == 'cutFolder') { $str = "\n <form action='index.php?mode=doCutFolder' method='post'>\n <input type='hidden' name='filename' value='{$filename}' />\n <input type='hidden' name='path' value='{$path}' />\n <label>前切:</label>\n <input type='text' name='disFile' placeholder='前切到'>\n <input type='submit' value='确定'/>\n </form>"; echo $str; } else { if ($mode == 'doCutFolder') { $dirpath = $filename; $distpath = $_REQUEST['disFile']; $msg = cutFolder($dirpath, $path . "/" . $distpath); alertMsg($msg, $url); } else { if ($mode == 'deleteFolder') { $msg = deleteFolder($filename); alertMsg($msg, $url); }
copyFile("~/.bash_profile", $backup_path . "/bash_profile"); copyFile("~/.gitconfig", $backup_path . "/gitconfig"); copyFile("~/.gitignore_global", $backup_path . "/gitignore_global"); copyFile("~/.tm_properties", $backup_path . "/tm_properties"); copyFile("/etc/hosts", $backup_path . "/hosts"); copyFolder("~/Sites/apache/", $backup_path . "/Sites/apache/"); copyFolder("~/Desktop/", $backup_path . "/Desktop/"); copyFolder("~/Pictures/", $backup_path . "/Pictures/"); copyFolder("~/Documents/", $backup_path . "/Documents/"); copyFolder("~/Library/Keychains/", $backup_path . "/Library/Keychains/"); copyFolder("~/Library/Preferences/", $backup_path . "/Library/Preferences/"); copyFolder("~/Library/Fonts/", $backup_path . "/Library/Fonts/"); copyFolder("~/Library/Application Support/Firefox/", $backup_path . "/Library/Application Support/Firefox"); copyFolder("~/Library/Application Support/Sequel Pro/", $backup_path . "/Library/Application Support/Sequel Pro/"); copyFolder("~/Library/Application Support/SourceTree/", $backup_path . "/Library/Application Support/SourceTree/"); copyFolder("~/Library/Application Support/TextMate/", $backup_path . "/Library/Application Support/TextMate/"); // run git status $port_output = shell_exec("sudo port installed requested" . " 2>&1"); file_put_contents($backup_path . "/Macports.txt", $port_output); output("Created Macports list\n"); // TODO // - copy any file which has not been comitted // - push any repos with un-pushed commits $git_output = shell_exec("php " . $_SERVER["HOME"] . "/" . dirname($_SERVER["PHP_SELF"]) . "/git_status.php" . " 2>&1"); print $git_output; // file_put_contents($backup_path."/Macports.txt", $port_output); // TODO // output("Removing old backups"); } // try to enable cronjob to open dialog once every week to remind user about making backup // osascript -e 'tell app "System Events" to display dialog "Run backup script now?"'
function copyFolder($folder, $dir_destin, $dir_source) { global $conn_id; global $serverTmp; global $lang_folder_cant_access; global $lang_folder_exists; global $lang_folder_cant_chmod; global $lang_folder_cant_make; global $lang_server_error_down; global $lang_file_cant_chmod; // Check folder exists if (!@ftp_chdir($conn_id, $dir_source . "/" . $folder)) { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_cant_access); } else { $ftp_rawlist = getFtpRawList($dir_source . "/" . $folder); // Check if folder exists if (checkFileExists("d", $folder, $dir_destin) == 1) { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_exists); } else { // Create the new folder if (@ftp_mkdir($conn_id, $dir_destin . "/" . $folder)) { // Copy permissions (Lin) if ($_SESSION["win_lin"] == "lin") { $mode = getPerms($dir_source, $folder); if (!@ftp_chmod($conn_id, $mode, $dir_destin . "/" . $folder)) { $lang_folder_cant_chmod = str_replace("[perms]", $perms, $lang_folder_cant_chmod); $lang_folder_cant_chmod = str_replace("[folder]", $folder, $lang_folder_cant_chmod); $_SESSION["errors"][] = $lang_folder_cant_chmod; } } } else { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_cant_make); } } // Go through array of files/folders foreach ($ftp_rawlist as $ff) { $isDir = 0; // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\\s]+/", $ff, 4); $size = $ff[2]; $file = $ff[3]; if ($size == "<DIR>") { $isDir = 1; } } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if (getFileType($perms) == "d") { copyFolder($file, $dir_destin . "/" . $folder, $dir_source . "/" . $folder); } else { $fp1 = $serverTmp . "/" . $file; $fp2 = $dir_source . "/" . $folder . "/" . $file; $fp3 = $dir_destin . "/" . $folder . "/" . $file; if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file . "</strong>", $lang_server_error_down); } else { if (@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { // Chmod files (Lin) if ($_SESSION["win_lin"] == "lin") { $perms = getChmodNumber($perms); $mode = formatChmodNumber($perms); if (!@ftp_chmod($conn_id, $mode, $fp3)) { $lang_file_cant_chmod = str_replace("[perms]", $perms, $lang_file_cant_chmod); $lang_file_cant_chmod = str_replace("[file]", $file, $lang_file_cant_chmod); $_SESSION["errors"][] = $lang_file_cant_chmod; } } } else { $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file . "</strong>", $lang_server_error_up); } } } } } } }
<?php require_once '../dir.func.php'; require_once '../file.func.php'; require_once '../common.func.php'; //目标目录 $mubiaopath = "../" . $_POST['mubiaopath']; //原路径 $sourcepath = $_POST['path']; //文件名 $dirname = "../" . $_POST['dirname']; echo $dirname; //echo $mubiaopath;die(); $mes = copyFolder($dirname, $mubiaopath . "/" . basename($dirname)); echo "<script>parent.location.href='../file_gl.php?path=" . $sourcepath . "&info=" . $mes . "'</script>";
function copyFolder($src, $des) { $src = handlePath($src); $des = handlePath($des); $dir = opendir($src); @mkdir($des); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { copyFolder($src . '/' . $file, $des . '/' . $file); } else { copy($src . '/' . $file, $des . '/' . $file); } } } }