/** * Remove a directory if it exists. * * @param string $dirName The full path of the directory to remove * @param boolean $recursive Should I remove its contents recursively? Otherwise it will fail if the directory * is not empty. * * @return mixed */ public function rmdir($dirName, $recursive = true) { $ret = $this->fileAdapter->rmdir($dirName, $recursive); if (!$ret && is_object($this->abstractionAdapter)) { return $this->abstractionAdapter->rmdir($dirName, $recursive); } return $ret; }
public static function upload($model, $modelName, $name, $attribute, $removePastImage = true, $sizes = array()) { $uploadOptions = $attribute["uploadOptions"]; $path = "public"; $beforeImage = $model->{$name}; if (isset($uploadOptions["sizes"])) { $sizes = $uploadOptions["sizes"]; } if (isset($uploadOptions["path"])) { $path = $uploadOptions["path"]; } $files = Input::file($name); if ($files["name"] == "") { return false; } $extension = File::extension($files["name"]); $directory = path($path) . $uploadOptions["directory"]; $nameFile = sha1(Session::has("token_user") . microtime()); $filename = "{$nameFile}.{$extension}"; $fullPath = $directory . "/" . $filename; $defaultImage = $directory . "/" . $filename; $defaultImageName = $filename; $successUpload = Input::upload($name, $directory, $filename); if ($successUpload === false) { return false; } if (File::exists($directory . "/" . $beforeImage)) { File::delete($directory . "/" . $beforeImage); } var_dump($beforeImage); $beforeExtension = File::extension($beforeImage); $preg = $directory . "/" . preg_replace("/\\.{$beforeExtension}/", "", $beforeImage); if (!empty($beforeImage)) { foreach (glob("{$preg}*", GLOB_ONLYDIR) as $key => $dir) { File::rmdir($dir); } } foreach ($sizes as $key => $size) { if (!preg_match("/\\d*x\\d*/", $size)) { throw new Exception("Size doesnt have a valid format valid for {$size} example: ddxdd", 1); } if (!class_exists("Resizer")) { throw new Exception("Bundle Resizer must be installed <br> Please got to <a href='http://bundles.laravel.com/bundle/resizer'>http://bundles.laravel.com/bundle/resizer</a>", 1); } $filename = $nameFile . "_{$key}.{$extension}"; $sizeOptions = preg_split("/x/", $size); $fullPath = $directory . "/{$nameFile}{$key}/" . $filename; $beforeImageWithSize = $directory . "/{$nameFile}{$key}/" . $beforeImage; if (!is_dir($directory . "/" . $nameFile . $key)) { mkdir($directory . "/" . $nameFile . $key, 0777); } $success = Resizer::open($defaultImage)->resize($sizeOptions[0], $sizeOptions[1], 'fit')->save($fullPath, 90); if ($success === false) { return false; } } return array("fullPath" => $defaultImage, "fileName" => $defaultImageName); }
public function get_delete($id, $redirect = null) { if (is_null($redirect)) { $redirect = ''; } $room = Room::find($id); $room->delete(); $path_kamer_folder = 'public_html/img/room/' . $id; File::rmdir($path_kamer_folder); return Redirect::to('admin/' . $redirect)->with('msg', '<div class="alert alert-warning"><strong>Kamer verwijderd</strong></div>'); }
public function run() { Bundle::start('messages'); $today = date('Y-m-d'); $rooms = Room::where_del_date($today)->get(); foreach ($rooms as $room) { Message::send(function ($message) use($room) { $message->to($room->email); $message->from('*****@*****.**', 'Kamergenood'); $message->subject('Kamer verlopen en verwijderd: "' . $room->title . '"'); $message->body('view: emails.deleted'); $message->body->title = $room->title; $message->html(true); }); $path_room_folder = getcwd() . '/public_html/img/room/' . $room->id; File::rmdir($path_room_folder); $room->delete(); } }
private function clean($key, $force = false) { $now = time(); $file = $this->getFile('expires.' . $key . '.5'); $path = str_replace(DS . Arrays::last(explode(DS, $file)), '', $file); if (is_dir($path)) { $files = glob($path . DS . '*.php'); if (!empty($files)) { $when = (int) str_replace([$path . DS, '.php'], '', Arrays::first($files)); if ($when < $now || true === $force) { File::rmdir($path); $this->remove($key); } } } else { if (true === $force) { $this->remove($key); } } return $this; }
public function delete_painting() { $name = $this->name; $tags = $this->tags; if ($tags) { foreach ($tags as $tag) { $tag->count = $tag->count - 1; if ($tag->count <= 0) { $tag->delete(); } else { $tag->save(); } } } if ($this->delete()) { $directory = path('public') . 'uploads/paintings/' . sha1($name); File::rmdir($directory); return true; } else { return false; } }
public function post_slideshow($num) { $input = Input::all(); if (empty($input["image{$num}"])) { $image = DB::table('slideshow_images')->where('number', '=', $num)->first(); if ($image) { $affected = DB::table('slideshow_images')->where('number', '=', $num)->delete(); if ($affected) { $directory = path('public') . 'uploads/slideshow/' . sha1("image{$num}"); File::rmdir($directory); } return Redirect::to(URL::to_route('dashboard.slideshow'))->with('status_success', __('application.slideshow_deleted')); } } try { $validator = new Services\Dashboard\Slideshow\Validator($input, $num); $validator->publish(); } catch (ValidateException $errors) { return Redirect::to(URL::to_route('dashboard.slideshow'))->with_input()->with_errors($errors->get()); } $errors = new Laravel\Messages(); $extension = File::extension($input["image{$num}"]['name']); $directory = path('public') . 'uploads/slideshow/' . sha1("image{$num}"); $filename = "original.{$extension}"; $upload_success = ImageUtils::upload_slideshow("image{$num}", $directory, $filename); $image_path = URL::base() . '/uploads/slideshow/' . sha1("image{$num}"); if ($upload_success) { $image = DB::table('slideshow_images')->where('number', '=', $num)->first(); if ($image) { DB::table('slideshow_images')->where('number', '=', $num)->update(array('image_path' => $image_path)); } else { DB::table('slideshow_images')->insert(array('number' => $num, 'image_path' => $image_path)); } return Redirect::to(URL::to_route('dashboard.slideshow'))->with('status_success', __('application.slideshow_added')); } else { $errors->add('errors', __('application.generic_error')); return Redirect::to(URL::to_route('dashboard.slideshow'))->with_input()->with_errors($errors); } }
public static function remove($module_slug) { if (isset($module_slug) and !empty($module_slug)) { // Remove bundle files if (\File::rmdir(path('bundle') . $module_slug) === null) { static::$errors->add('installer', 'Module [' . $module_slug . '] was successfully removed.'); // // Remove published assets // if (File::rmdir(path('public') . 'bundles' . DS . $module_slug) === null) { static::$errors->add('installer', 'Module assets for module [' . $module_slug . '] were successfully removed.'); return true; } else { static::$errors->add('installer', 'Failed to remove assets for module [' . $module_slug . '].'); return false; } } else { static::$errors->add('installer', 'Failed to remove module [' . $module_slug . '].'); return false; } } else { static::$errors->add('installer', 'Failed to remove module, invalid module slug'); return false; } }
public function clear_act() { $info = array('status' => 'fail', 'msg' => '缓存清理失败!'); if (File::rmdir(APP_ROOT . 'runtime') && File::rmdir(APP_ROOT . 'cache')) { $info = array('status' => 'success', 'msg' => '缓存已成功清理!'); } echo JSON::encode($info); }
public function post_delete($city, $id, $delkey) { $rules = array('id' => 'required', 'delkey' => 'required|max:60', 'email' => 'required|email'); $values = array('id' => $id, 'delkey' => $delkey, 'email' => Input::get('email')); $v = Validator::make($values, $rules); $room = Room::find($id); if ($v->fails()) { return View::make('home.room')->with('del', '<div id="delModal" class="modal hide" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="myModalLabel">Kamer verwijderen</h3></div><div class="modal-body"><p>Vul ter verificatie je e-mailadres in om de kamer te verwijderen.</p><form action="' . $delkey . '" method="post" class="form-horizontal"><div class="control-group"><label class="control-label" for="email">Email:</label><div class="controls"><input type="email" name="email" class="span8" placeholder="Je e-mail" data-validations="required|email"><p class="error-bottom">Vul a.u.b een emailadres in</p></div></div><div class="control-group"><label class="control-label" for="reason">Reden:</label><div class="controls"><label class="radio"><input type="radio" name="reason" value="Verhuurd"> <strong>Huisgenoot gevonden, bedankt!</strong></label><label class="radio"><input type="radio" name="reason" value="Andere kamerwebsite"> Verhuurd via andere kamerwebsite</label><label class="radio"><input type="radio" name="reason" value="Geen reacties"> Geen reacties gekregen</label><label class="radio"><input type="radio" name="reason" value="Ontevreden"> Ontevreden over kamergenood</label></div></div></div><div class="modal-footer"><button class="btn btn-danger" type="submit">Verwijder kamer</button></form></div></div>')->with('room', $room); } else { if ($room->delkey == $delkey && $room->email == Input::get('email')) { $room->delete(); $path_kamer_folder = 'public_html/img/room/' . $id; File::rmdir($path_kamer_folder); return Redirect::to('kamer-verhuren'); } else { return View::make('home.room')->with('del', '<div id="delModal" class="modal hide" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="myModalLabel">Kamer verwijderen</h3></div><div class="modal-body"><div class="alert alert-error"><strong>Onjuist emailadres!</strong> Dit emailadres is niet bekend bij ons </div><form action="' . $delkey . '" method="post" class="form-horizontal"><div class="control-group"><label class="control-label" for="email">Email:</label><div class="controls"><input type="email" name="email" class="span8" placeholder="Je e-mail" data-validations="required|email"></div></div><div class="control-group"><label class="control-label" for="reason">Reden:</label><div class="controls"><label class="radio"><input type="radio" name="reason" value="Verhuurd"> <strong>Huisgenoot gevonden, bedankt!</strong></label><label class="radio"><input type="radio" name="reason" value="Andere kamerwebsite"> Verhuurd via andere kamerwebsite</label><label class="radio"><input type="radio" name="reason" value="Geen reacties"> Geen reacties gekregen</label><label class="radio"><input type="radio" name="reason" value="Ontevreden"> Ontevreden over kamergenood</label></div></div></div><div class="modal-footer"><button class="btn btn-danger" type="submit">Verwijder kamer</button></form></div></div>')->with('room', $room); } } }
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && $oldFile["path"] == $file["path"]) { $found = true; break; } } if (!$found) { File::delete(static::storagePath() . $oldFile["path"]); } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { File::delete(static::storagePath() . $oldFile["path"]); } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $unique = static::unique($destPath . $file["_name"]); File::move(static::tmpPath() . $file["_tmpName"], $unique); $files[$k] = array("path" => $path . File::fileName($unique), "caption" => array_key_exists('caption', $file) ? $file['caption'] : ""); } } $this->module->orm->setField($this->name, json_encode($files)); } }
public function delete_destroy($theme_slug) { if (!isset($theme_slug) or empty($theme_slug)) { $this->data['message'] = __('themes::lang.Cannot delete invalid theme name')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::back()->with($this->data); } $theme = \Themes\Model\Theme::where('slug', '=', $theme_slug)->first(); if (isset($theme)) { // do not delete theme if is defatul if ($theme->is_default == 1) { $this->data['message'] = __('themes::lang.Selected as default')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); // do not delete theme if is a core theme if ($theme->is_core == 1) { $this->data['message'] = __('themes::lang.A core theme cannot be deleted')->get(ADM_LANG); $this->data['message_type'] = 'error'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message']))); return json_encode($data); } return Redirect::to(ADM_URI . '/themes')->with($this->data); } } // Theme is not core and is // not enabled. Remove it $theme->delete(); } $path = path('public') . 'themes' . DS . $theme_slug; \File::rmdir($path); $this->data['message'] = __('themes::lang.Theme was successfully destroyed')->get(ADM_LANG); $this->data['message_type'] = 'success'; if (Request::ajax()) { $data = array('flash_message' => array('message_type' => $this->data['message_type'], 'messages' => array($this->data['message'])), 'hide' => array('identifier' => 'tr#theme-' . $theme_slug)); return json_encode($data); } return Redirect::back()->with($this->data); }
public function post_delete($galleryID) { Galleries::delete($galleryID); File::rmdir(path('public') . 'images/' . $galleryID); return Redirect::to('admin/galleries'); }
public function run() { $path_room_folder = getcwd() . '/public_html/img/room/45'; File::rmdir($path_room_folder); }
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && current($oldFile) == current($file)) { $found = true; break; } } if (!$found) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $samples = array(); $im = new Image(); $i = 0; $tmpPath = static::tmpPath() . $file["_tmpName"]; foreach ($this->samples as $k2 => $sample) { //if ($k2 == 0) //{ $im->load($tmpPath); //} if (!array_key_exists("width", $sample)) { $sample["width"] = 0; } if (!array_key_exists("height", $sample)) { $sample["height"] = 0; } if ($sample["width"] != 0 || $sample["height"] != 0) { $im->resize($sample["width"], $sample["height"], $sample["resizeMethod"], $sample["background"]); } if ($this->customFilters) { foreach ($this->customFilters as $filter) { call_user_func($filter, $im); } } $fileName = $file["_name"]; if ($sample["key"] != "original") { $fileName = File::removeExtension($file["_name"]) . "-" . $sample["key"] . "." . File::extension($file["_name"]); } $unique = static::unique($destPath . $fileName); $im->save($unique); $samples[$sample["key"]] = $path . File::fileName($unique); $samples["caption"] = array_key_exists('caption', $file) ? $file['caption'] : ""; $i++; } File::delete($tmpPath); $files[$k] = $samples; } } $this->module->orm->setField($this->name, json_encode($files)); } }
/** * Remove tenant folder from /tenants directory. * * @param string $name * @return bool */ private static function remove_tenant_folder($name) { if ($name == 'default') { throw new Exception("ERROR! You cannot remove the default tenant!"); } if (!file_exists(path('tenants') . $name)) { throw new Exception("ERROR! Directory for '{$name}' does not exist!"); return false; } return File::rmdir(path('tenants') . $name); }
public function deleteAll() { $native = Config::get('dir.ephemere', session_save_path()); File::rmdir($native); return $this; }