function printDir($dir) { global $highlight; if (is_file($dir)) { // a file was supplied as a directory editFile($dir); return; } $entries = @scandir(realpath($dir)); if ($entries === false) { echo '<strong>Error:</strong> Cannot open directory.'; return; } if (count($entries) <= 2) { echo 'Empty directory'; return; } echo ' <table class="data"> <th> </th><th width="350">Name</th><th width="90">Bytes</th><th width="150">Changed</th><th> </th><th> </th><th> </th>'; foreach ($entries as $z => $i) { if (preg_match('/^\\.+$/', $i)) { continue; } $path = realpath("{$dir}/{$i}"); //$shade = $z % 2 ? '' : ' class="shaded"'; //$shade = ''; $shade = strtolower($i) == strtolower($highlight) ? ' class="highlighted"' : ''; $change = date('j/m/Y g:ia', filectime($path)); if (is_dir($path)) { // directory echo "\r\n<tr{$shade} id=\"row{$z}\" onmouseover=\"changeHighlightState(this, true)\" onmouseout=\"changeHighlightState(this, false)\">\r\n\t<td><a class=\"icon\" href=\"#\" onclick=\"browseDir(pathFromID({$z}))\"><font size=\"4\">Dir</font></a></td>\r\n\t<td>\r\n\t\t<input type=\"hidden\" id=\"path{$z}\" value=\"" . html($path) . "\" />\r\n\t\t<input type=\"hidden\" id=\"filename{$z}\" value=\"" . html($i) . "\" />\r\n\t\t<a href=\"#\" onclick=\"browseDir(pathFromID({$z}))\" id=\"link{$z}\">" . html($i) . "</a>\r\n\t\t<form action=\"javascript://\" onsubmit=\"rename({$z})\" class=\"compact\">\r\n\t\t\t<input type=\"text\" id=\"label{$z}\" class=\"filelabel\" value=\"" . html($i) . "\" style=\"display: none\" />\r\n\t\t</form>\r\n\t</td>\r\n\t<td> </td>\r\n\t<td>{$change}</td>\r\n\t<td><font size=\"4\"><a href=\"javascript://\" class=\"icon\" onclick=\"del(pathFromID({$z}), filenameFromID({$z}), true, document.getElementById('row{$z}'))\"?>Delete</a></font></td>\n\t<td><font size=\"4\"><a href=\"javascript://\" class=\"icon\" onclick=\"toggleLabelEdit({$z})\">Rename</a></font></td>\r\n\t<td> </td>\r\n</tr>\r\n"; } else { // file $size = number_format(filesize($path), 0, '.', ','); echo "\r\n<tr{$shade} id=\"row{$z}\" onmouseover=\"changeHighlightState(this, true)\" onmouseout=\"changeHighlightState(this, false)\">\r\n\t<td><a class=\"icon\" href=\"#\" onclick=\"goto('?action=dl&s=' + pathFromID({$z}))\"><font size=\"4\">File</font></a></td>\r\n\t<td>\r\n\t\t<input type=\"hidden\" id=\"path{$z}\" value=\"" . html($path) . "\" />\r\n\t\t<input type=\"hidden\" id=\"filename{$z}\" value=\"" . html($i) . "\" />\r\n\t\t<a href=\"#\" onclick=\"goto('?action=dl&s=' + pathFromID({$z}))\" id=\"link{$z}\">" . html($i) . "</a>\r\n\t\t<form action=\"javascript://\" onsubmit=\"rename({$z})\" class=\"compact\">\r\n\t\t\t<input type=\"text\" id=\"label{$z}\" class=\"filelabel\" value=\"" . html($i) . "\" style=\"display: none\" />\r\n\t\t</form>\r\n\t</td>\r\n\t<td>{$size}</td>\r\n\t<td>{$change}</td>\r\n\t<td><font size=\"4\"><a href=\"javascript://\" class=\"icon\" onclick=\"del(pathFromID({$z}), filenameFromID({$z}), false, document.getElementById('row{$z}'))\"?>Delete</a></font></td>\n\t<td><font size=\"4\"><a href=\"javascript://\" class=\"icon\" onclick=\"toggleLabelEdit({$z})\">Rename</a></font></td>\r\n\t<td><font size=\"4\"><a href=\"#\" onclick=\"goto('?action=edit&s=' + pathFromID({$z}))\" class=\"icon\">Edit</a></font></td>\r\n</tr>\r\n"; } } echo '</table>'; }
function processActions() { $ftpAction = ''; if (isset($_POST["ftpAction"]) && !empty($_POST["ftpAction"])) { $ftpAction = $_POST["ftpAction"]; } elseif (isset($_GET["ftpAction"]) && !empty($_GET["ftpAction"])) { $ftpAction = $_GET["ftpAction"]; } else { $ftpAction = 'error'; } // Open folder (always called) if (openFolder() == 1) { // New file if ($ftpAction == "newFile") { newFile(); } // New folder if ($ftpAction == "newFolder") { newFolder(); } // Upload file if ($ftpAction == "upload") { uploadFile(); } // Cut if ($ftpAction == "cut") { cutFilesPre(); } // Copy if ($ftpAction == "copy") { copyFilesPre(); } // Paste if ($ftpAction == "paste") { pasteFiles(); } // Delete if ($ftpAction == "delete") { deleteFiles(); } // Rename if ($ftpAction == "rename") { renameFiles(); } // Chmod if ($ftpAction == "chmod") { chmodFiles(); } // Drag & Drop if ($ftpAction == "dragDrop") { dragDropFiles(); } // Edit if ($ftpAction == "edit") { editFile(); } } }
// 書き込めるファイルを限定する $writable_files = array('p2_aborn_res.txt' => 'あぼーんレス'); if (!array_key_exists($filename, $writable_files)) { $files_st = implode(', ', array_keys($writable_files)); p2die(basename($_SERVER['SCRIPT_NAME']) . " 先生の書き込めるファイルは、{$files_st}だけ!"); } $path = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . $filename; //========================================================= // メイン //========================================================= if (isset($filecont)) { if (setFile($path, $filecont, $encode)) { P2Util::pushInfoHtml('saved, OK.'); } } editFile($path, $encode, $writable_files[$filename]); exit; //========================================================= // 関数 //========================================================= // {{{ setFile() /** * ファイルに内容をセットする関数 */ function setFile($path, $cont, $encode) { if ($path == '') { p2die('path が指定されていません'); } if ($encode == "EUC-JP") { $cont = mb_convert_encoding($cont, 'CP932', 'CP51932');
* @category Loris * @package Media * @author Alex I. <*****@*****.**> * @license Loris license * @link https://github.com/aces/Loris-Trunk */ if (isset($_GET['action'])) { $action = $_GET['action']; if ($action == "getData") { echo json_encode(getUploadFields()); } else { if ($action == "upload") { uploadFile(); } else { if ($action == "edit") { editFile(); } } } } /** * Handles the media update/edit process * * @throws DatabaseException * * @return void */ function editFile() { $db =& Database::singleton(); $user =& User::singleton();
function fileManager() { if ($_SESSION['adminType'] == 'sadmin') { $fileManPath = RAZOR_SADMIN_PATH; } else { $fileManPath = RAZOR_FILEMAN_PATH; } // set upload limits if server permits // @ini_set('upload_max_filesize', '100M'); @ini_set('post_max_size', '105M'); @ini_set('memory_limit', '205M'); @ini_set('max_execution_time', '300'); // end of set // $dirToView = ''; $dirFound = false; $fileFound = false; if (isset($_GET['dir']) && $_GET['dir']) { // get sub dir from url // $subDir = $_GET['dir']; // ensure no one has injected url, force to correct format // // IMPORTANT - TO PREVENT ACCESS TO OTHER AREAS ON SERVER // $subDir = str_replace('/', '>', $subDir); $subDir = str_replace('..', '', $subDir); // change to path format // $subDir = str_replace('>', '/', $subDir); if (is_dir(getSystemRoot(RAZOR_ADMIN_FILENAME) . $fileManPath . $subDir)) { $dirToView = $subDir . '/'; $dirFound = true; } elseif (file_exists(getSystemRoot(RAZOR_ADMIN_FILENAME) . $fileManPath . $subDir)) { $dirToView = $subDir; $fileFound = true; } // remove user level ability to do anything with restricted files // if ($_SESSION['adminType'] == 'user') { $noAccessArray = noReadWriteAccess(); if (in_array($dirToView, $noAccessArray)) { return; } } } if (isset($_GET['del']) && $_GET['del']) { if ($dirFound) { $dirArray = array(); if (substr($dirToView, -1) == '/') { $dirToView = substr($dirToView, 0, -1); } $dirArray = explode('/', $dirToView); array_pop($dirArray); $verifyDir = implode('/', $dirArray) . '/'; if (is_dir(getSystemRoot(RAZOR_ADMIN_FILENAME) . $fileManPath . $verifyDir)) { $dirDelRes = deleteDirR($fileManPath . $dirToView); if (!$dirDelRes) { MsgBox(lt('Folder and contents deleted') . '...', 'greenbox'); } else { MsgBox(lt('Error deleting folder and contents') . '...', 'redbox'); } $dirToView = $verifyDir; } } elseif ($fileFound) { $verifyFile = str_replace(basename($dirToView), '', $dirToView); if (is_dir(getSystemRoot(RAZOR_ADMIN_FILENAME) . $fileManPath . $verifyFile)) { deleteFile($fileManPath . $dirToView); $dirToView = $verifyFile; } } } if (isset($_POST['upload'])) { uploadFiles(); } if (isset($_POST['rename'])) { renameFileDir(); } if (isset($_POST['copy'])) { copyFileDir(); } if (isset($_POST['move'])) { moveFileDir(); } if (isset($_POST['createnewdir'])) { createNewDir(); } if (isset($_POST['edit'])) { editFile(); } $filesPath = getSystemRoot(RAZOR_ADMIN_FILENAME) . $fileManPath . $dirToView; if (is_dir($filesPath)) { if (isset($_GET['up']) && $_GET['up']) { displayFileUpload($dirToView); } elseif (isset($_GET['ren']) && $_GET['ren']) { displayRenameFileDir($dirToView, false); } elseif (isset($_GET['cop']) && $_GET['cop']) { displayCopyFileDir($dirToView, false); } elseif (isset($_GET['mov']) && $_GET['mov']) { displayMoveFileDir($dirToView, false); } elseif (isset($_GET['newdir']) && $_GET['newdir']) { displayCreateNewDir($dirToView); } else { $readFiles = array(); $readFiles = readDirContents($filesPath); BsocketB('admin-datastore-data', array(&$filesPath, &$readFiles)); displayDirContents($readFiles, $dirToView); } } elseif (file_exists($filesPath)) { if (isset($_GET['ren']) && $_GET['ren']) { displayRenameFileDir($dirToView, true); } elseif (isset($_GET['cop']) && $_GET['cop']) { displayCopyFileDir($dirToView, true); } elseif (isset($_GET['mov']) && $_GET['mov']) { displayMoveFileDir($dirToView, true); } elseif (isset($_GET['edit']) && $_GET['edit']) { displayEditFile($dirToView); } else { displayFileType($dirToView); } } }
$file .= ".txt"; $filepath = PATH_TO_FILES . "/{$file}"; if (file_exists($filepath)) { redirect_user('index.php', http_build_query(array('status_message' => "{$file} already exists"))); } else { if (file_put_contents($filepath, "") === false) { redirect_user('index.php', http_build_query(array('status_message' => "Couln't create file {$file}"))); } chmod($filepath, 0666); } return array($file, $filepath); } //---------------------- END FUNCTIONS ------------------------------- if ($_SERVER['REQUEST_METHOD'] == 'GET') { if (isset($_GET['filename'])) { list($filename, $filepath) = editFile($_GET['filename']); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { // If user hits cancel button, do nothing and return to home page if (isset($_POST["cancel"])) { redirect_user(); } if (isset($_POST["saveFile"])) { saveFile($_POST["filename"]); // saveFile() will return us to home page after it's done } if (isset($_POST["createFile"]) && isset($_POST['filename'])) { list($filename, $filepath) = createFile($_POST["filename"]); // createFile will either return us to home page or drop us into // edit page