function rename() { global $file; if (!trim(urldecode($file))) { $this->view->add2Content("_fmError" . MText::_("notforroot")); return; } if (!MRights::can("rename")) { $this->view->authError("rename"); return; } $file = _START_FOLDER . urldecode($file); $newName = MRequest::clean("newname"); $newName = end(preg_split("/[\\/\\,]+/", $newName)); $info = MFile::info($file); $new = $info->dirName . DS . $newName; if (!file_exists($new)) { if (MFile::rename($file, $new)) { $this->view->add2Content("ok"); return null; } else { $this->view->add2Content("_fmError"); } } else { $this->view->add2Content("_fmError"); } }
public static function liveTests(){ // Set Sandbox to be writable if possible @MFile::chmod(_FM_SANDBOX, 755); if( ! MFile::isWritable(_FM_SANDBOX)){ self::$sandboxError = 1; return false; } $assets = _FM_SANDBOX .DS . "assets" ; $fileSample = _FM_SANDBOX .DS . "assets" . DS ."sample.txt"; $fileValidate = _FM_SANDBOX .DS . "assets" . DS ."validate.txt"; $destinationFolder = _FM_SANDBOX . DS . "dest"; // 1. isDir self::$params["live_is_dir"] = (int) @MFile::isDir($assets); // 2. isFile self::$params["live_is_file"] = (int) @MFile::isFile($fileSample); // 3. Create Dir MFile::createDir($destinationFolder, 0755); self::$params["live_create_dir"] = (int) ( @MFile::is($destinationFolder) && @MFile::isDir($destinationFolder)); // 4. Read $valid = MFile::readData($fileValidate); self::$params["live_read_file"] = (int) $valid == "valid"; // 5. Copy MFile::copy($fileValidate, $destinationFolder . DS . basename($fileValidate)); // MFile::copy($fileValidate, _FM_SANDBOX . DS . "reserved.txt"); self::$params["live_copy"] = (int) MFile::is($destinationFolder . DS . basename($fileValidate)); // 6. Rename $newValidate = $destinationFolder . DS . "deleteme.txt"; MFile::rename($destinationFolder . DS . basename($fileValidate), $newValidate); self::$params["live_rename"] = (int) MFile::is($newValidate); // 7. mode read @MFile::chmod($newValidate, 444); $mode = MFile::mode($newValidate); self::$params["live_mode"] = (int) (!! $mode); // 8. CHMOD MFile::chmod($newValidate, 666); self::$params["live_chmod"] = (int) ( $mode != MFile::mode($newValidate) ); // 9. Write (Create / Add File) MFile::writeData($newValidate,"new",true); $validnew = MFile::readData($newValidate); self::$params["live_write_file"] = (int) $validnew == "validnew"; // 10. Pack $archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip'); $archive->add($destinationFolder,PCLZIP_OPT_REMOVE_PATH, $destinationFolder); self::$params["live_zip"] = (int) MFile::is(_FM_SANDBOX. DS . 'packed.zip'); // 11. Delete File MFile::remove($newValidate, 1); self::$params["live_delete_file"] = (int) ! MFile::is($newValidate); // 12. Delete Folder MFile::removeDir($destinationFolder); self::$params["live_delete_folder"] = (int) ! MFile::is($destinationFolder); // 13. UNZIP $archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip'); $archive->extract(PCLZIP_OPT_PATH, _FM_SANDBOX); self::$params["live_unzip"] = (int) MFile::is(_FM_SANDBOX. DS . 'deleteme.txt'); // 14. Move MFile::createDir($destinationFolder, 0777); MFile::move(_FM_SANDBOX. DS . 'deleteme.txt', $destinationFolder); self::$params["live_move"] = (int) MFile::is($newValidate); // Purge MFile::remove(_FM_SANDBOX. DS . 'packed.zip', 1); MFile::removeDirAtAllCosts($destinationFolder); }
function rename() { global $file; if (!MRights::can("rename")) { $this->popupError("rename"); return; } $file = _START_FOLDER . urldecode($file); $newName = MRequest::clean("newname"); $newName = end(preg_split("/[\\/\\,]+/", $newName)); $info = MFile::info($file); $new = $info->dirName . DS . $newName; $this->view->add2Content('<div style="display:none;">' . md5(uniqid()) . '</div>'); MFile::rename($file, $new); $this->view->add2Content(fmGetFiles()); }