action="load";'; // Determine what to do based on mime type $finfo = finfo_open(FILEINFO_MIME_TYPE); if (strpos(finfo_file($finfo, $file),"text")===0) { if (file_exists($file)) { echo ''; $loadedFile = file_get_contents($file); echo '","",htmlentities($loadedFile)).''; } else { echo ''; } } else if (strpos(finfo_file($finfo, $file),"image")===0) { echo ''; } else { echo ''; }; finfo_close($finfo); }; // If we're due to add a new folder... if ($_GET['action']=="newFolder") { if (!$demoMode && is_writable($docRoot.$fileLoc)) { mkdir($file, 0705); // Reload file manager echo ''; } else { echo ""; } echo ''; } // If we're due to paste a new file... if ($_GET['action']=="paste") { $source = $file; $dest = $docRoot.strClean(str_replace("|","/",$_GET['location']))."/".basename($source); if (!$demoMode && is_writable(dirname($dest))) { if (is_dir($source)) { if (!is_dir($dest)) { mkdir($dest, 0705); } foreach ($iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item ) { if ($item->isDir()) { mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0705); } else { copy($item, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName()); } } } else { copy($source, $dest); } // Reload file manager echo ''; } else { echo ""; } echo ''; } // If we're due to rename a file/folder... if ($_GET['action']=="rename") { if (!$demoMode && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) { rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName); // Reload file manager echo ''; } else { echo ""; } echo ''; } // If we're due to replace text in a file... if ($_GET['action']=="replaceText") { if (!$demoMode && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) { $file = str_replace("|","/",strClean($_GET['fileRef'])); $loadedFile = file_get_contents($file); $newContent = str_replace(strClean($_GET['find']),strClean($_GET['replace']),$loadedFile); $fh = fopen($file, 'w') or die("Sorry, cannot save"); fwrite($fh, $newContent); fclose($fh); echo ''; } else { echo ""; } echo ''; } // If we're due to change permissions on a file/folder... if ($_GET['action']=="perms") { if (!$demoMode && is_writable($file)) { chmod($file,octdec(numClean($_GET['perms']))); // Reload file manager echo ''; } else { echo ""; } echo ''; } // If we're due to delete a file... if ($_GET['action']=="delete") { $filesArray = explode(";",$file); // May contain more than one file here for ($i=0;$i<=count($filesArray)-1;$i++) { if (!$demoMode && is_writable($iceRoot.$filesArray[$i])) { is_dir($iceRoot.$filesArray[$i]) ? rrmdir($iceRoot.$filesArray[$i]) : unlink($iceRoot.$filesArray[$i]); // Reload file manager echo ''; } else { echo ""; } echo ''; } echo ''; } // The function to recursively remove folders & files function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { filetype($dir."/".$object) == "dir" ? rrmdir($dir."/".$object) : unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } if ($_GET['action']=="save") { echo ''; // on the form posting via a reload, save the file if (isset($_POST['contents'])) { if (!$demoMode && ((file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && $_POST['newFileName']!="")) { if (filemtime($file)==$_GET['fileMDT']||!(isset($_GET['fileMDT']))) { $fh = fopen($file, 'w') or die("Sorry, cannot save"); fwrite($fh, $_POST['contents']); fclose($fh); clearstatcache(); echo ''; // Reload file manager & rename tab if it was a new file if (isset($_POST['newFileName']) && $_POST['newFileName']!="") { echo ''; } // Reload stickytab window echo ''; } else { $loadedFile = file_get_contents($file); echo '","",htmlentities($loadedFile)).''; echo ''; ?> action='nothing';top.ICEcoder.message('Sorry, cannot write\\n".$file."')"; } echo ''; } }; ?>