本文整理汇总了PHP中Illuminate\Support\Facades\Storage::move方法的典型用法代码示例。如果您正苦于以下问题:PHP Storage::move方法的具体用法?PHP Storage::move怎么用?PHP Storage::move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Storage
的用法示例。
在下文中一共展示了Storage::move方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Rename the file directory to rename the file in the system
*
*/
public function handle()
{
if (Storage::exists($this->getOldFileDirectory())) {
Storage::move($this->getOldFileDirectory(), $this->getNewFileDirectory());
}
event(new FileWasRenamed($this->from, $this->to));
}
示例2: register
/**
* User registration
*
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/
public function register(Request $request)
{
if ($request->isMethod('post')) {
$rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username', 'email' => 'required|email|unique:users,email', 'pass' => 'required|min:6|max:12', 'pass_confirmation' => 'required|min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png'];
Validator::make($request->all(), $rules)->validate();
$user = new User();
$user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name');
$user->position = $request->input('position');
$user->role_id = 2;
if ($request->has('phone')) {
$user->phone = $request->input('phone');
}
if (!empty($request->file("image"))) {
$generated_string = str_random(32);
$file = $request->file("image")->store('uploads');
$new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('image'));
$img->crop(200, 200);
$img->save(storage_path('app/public/uploads/' . $new_file));
$user->image = $new_file;
}
$user->username = $request->input('username');
$user->email = $request->input('email');
$user->password = Hash::make($request->input('pass'));
$user->activation_token = str_random(32);
$user->save();
return redirect('/');
} else {
return view('site.auth.register');
}
}
示例3: edit
/**
* Edit image
*
* @param Request $request
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function edit(Request $request, $id)
{
if ($request->isMethod("post")) {
$rules = ["link" => "url", 'image' => 'mimes:jpeg,jpg,png'];
Validator::make($request->all(), $rules)->validate();
$album_image = AlbumImage::getImageById($id);
$album_image->title = $request->input("title");
$album_image->link = $request->input("link");
if (!empty($request->file("image"))) {
if (!empty($album_image->image)) {
if (Storage::exists('uploads/' . $album_image->image) && Storage::exists('uploads/fb-' . $album_image->image)) {
Storage::delete('uploads/' . $album_image->image, 'uploads/fb-' . $album_image->image);
}
}
$generated_string = str_random(32);
$file = $request->file("image")->store('uploads');
$new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('image'));
$img->crop(200, 200);
$img->save(storage_path('app/public/uploads/' . $new_file));
$album_image->image = $new_file;
}
if ($request->has("album")) {
$album_image->album_id = $request->input("album");
}
$album_image->publish = $request->has("publish");
$album_image->save();
return redirect()->route('gallery');
} else {
$gallery = AlbumImage::getImageById($id);
$albums = Category::getCategoriesByContentType(3);
return view("admin.gallery.edit", compact("albums", "gallery"));
}
}
示例4: index
/**
* Site settings
*
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function index(Request $request)
{
$settings = Settings::getSettings();
if ($request->isMethod('post')) {
$rules = ['url' => 'required', 'email' => 'required|email', 'title' => 'required', 'desc' => 'required', 'keys' => 'required', 'logo' => 'mimes:jpeg,png', 'favicon' => 'mimes:jpeg,png'];
Validator::make($request->all(), $rules)->validate();
$settings->url = $request->input('url');
$settings->email = $request->input('email');
$settings->title = $request->input('title');
$settings->desc = $request->input('desc');
$settings->keys = $request->input('keys');
if (!empty($request->file("logo"))) {
if (Storage::exists('uploads/' . $settings->logo)) {
Storage::delete('uploads/' . $settings->logo);
}
$generated_string = str_random(32);
$file = $request->file("logo")->store('uploads');
$new_file = $generated_string . '.' . $request->file("logo")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('logo'));
$img->crop(200, 26);
$img->save(storage_path('app/public/uploads/' . $new_file));
$settings->logo = $new_file;
}
if (!empty($request->file("favicon"))) {
if (Storage::exists('uploads/' . $settings->favicon)) {
Storage::delete('uploads/' . $settings->favicon);
}
$generated_string = str_random(32);
$file = $request->file("favicon")->store('uploads');
$new_file = $generated_string . '.' . $request->file("favicon")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('favicon'));
$img->crop(16, 16);
$img->save(storage_path('app/public/uploads/' . $new_file));
$settings->favicon = $new_file;
}
if ($request->input('maintenance') == '0') {
Artisan::call('down');
} else {
Artisan::call('up');
}
$settings->maintenance = $request->input('maintenance');
$settings->save();
return redirect()->back();
} else {
return view('admin.settings', compact('settings'));
}
}
示例5: approveNewImage
/**
* Delete an old profile image and replace it with a new one.
* @param $userId
*/
public function approveNewImage($userId)
{
$sourceFilename = \App::environment() . '/user-photo/' . md5($userId) . '-new.png';
$sourceThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb-new.png';
$targetFilename = \App::environment() . '/user-photo/' . md5($userId) . '.png';
$targetThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb.png';
if (Storage::exists($targetFilename)) {
Storage::delete($targetFilename);
}
if (Storage::exists($targetThumbFilename)) {
Storage::delete($targetThumbFilename);
}
Storage::move($sourceFilename, $targetFilename);
Storage::move($sourceThumbFilename, $targetThumbFilename);
if (Storage::exists($sourceFilename)) {
Storage::delete($sourceFilename);
}
if (Storage::exists($sourceThumbFilename)) {
Storage::delete($sourceThumbFilename);
}
}
示例6: setFilenameAttribute
public function setFilenameAttribute($filename)
{
$oldFileName = !empty($this->attributes['filename']) ? $this->attributes['filename'] : '';
if (class_basename($filename) == 'UploadedFile') {
$this->attributes['filename'] = self::genName($filename);
$this->attributes['path'] = $this->attributes['filename'];
Storage::disk('local')->put($this->attributes['filename'], FileFacade::get($filename));
if ($oldFileName && Storage::exists($oldFileName)) {
Storage::delete($oldFileName);
}
} else {
if (is_string($filename) && is_file($filename)) {
$new_filename = basename($filename);
} else {
if ($filename && is_string($filename) && $oldFileName && $oldFileName != $filename) {
Storage::move($oldFileName, $filename);
} else {
$this->attributes['filename'] = $filename;
}
}
}
}
示例7: edit
/**
* Edit post
*
* @param Request $request
* @param int $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function edit(Request $request, $id = 0)
{
$post = Post::getPostById($id);
if (empty($post)) {
return redirect()->back();
} else {
if ($request->isMethod("post")) {
$rules = ["title" => "required", "alias" => "required|unique:posts,alias," . $id, "content" => "required", 'image' => 'mimes:jpeg,jpg,png'];
Validator::make($request->all(), $rules)->validate();
$post->title = $request->input("title");
$post->alias = $request->input("alias");
$post->content = $request->input("content");
$post->meta_keys = $request->input("meta_keys");
$post->meta_desc = $request->input("meta_desc");
if (!empty($request->file("image"))) {
if (!empty($post->image)) {
if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
}
}
$generated_string = str_random(32);
$file = $request->file("image")->store('uploads');
$new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('image'));
$img->crop(200, 200);
$img->save(storage_path('app/public/uploads/' . $new_file));
$img = Image::make($request->file('image'));
$img->resize(600, 315);
$img->save(storage_path('app/public/uploads/fb-' . $new_file));
$post->image = $new_file;
}
if ($request->has("category")) {
$post->category_id = $request->input("category");
}
$post->publish = $request->has("publish");
$post->save();
$new_tags = [];
if ($request->has("tags")) {
$tags = $request->input("tags");
foreach ($tags as $tag) {
array_push($new_tags, $tag);
}
}
$post->tags()->sync($new_tags);
return redirect()->route('posts');
} else {
$categories = Category::getCategoriesByPublish();
$tags = Tag::getTags();
return view("site.post.edit", compact("post", "categories", "tags"));
}
}
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$growPage = ReLinkSnips::find($id);
$data = $request;
$short_link = $data->domain . '/g/' . $data->url_path;
$data['short_link'] = $short_link;
$data['user_id'] = Auth::user()->id;
$rules = [];
if ($growPage->short_link == $data['short_link']) {
$rules = ['short_link' => 'exists:relink_snips'];
} else {
$rules = ['short_link' => 'unique:relink_snips'];
}
if ($request['type'] == 0) {
$rules = ['api' => 'required'];
}
$next_rules = ['second' => 'required|min:1|max:999|integer', 'btntxt' => 'required', 'btntxt_color' => 'required', 'btnurl' => 'required|url', 'type' => 'required', 'page_url' => 'required|url', 'domain' => 'required', 'url_path' => 'required', 'user_id' => 'exists:relink_snips', 'title' => 'required', 'title_color' => 'required', 'descrip' => 'required', 'descrip_color' => 'required', 'bg' => 'required'];
$rules_result = array_merge($rules, $next_rules);
$this->validate($data, $rules_result);
$fileName = $request->image;
if ($fileName != null) {
if (Storage::exists('/images/growpage/tmp/' . $fileName)) {
Storage::move('/images/growpage/tmp/' . $fileName, '/images/growpage/' . $fileName);
$data['upload_path'] = $fileName;
} elseif (Storage::exists('/images/growpage/' . $fileName)) {
$data['upload_path'] = $fileName;
}
} else {
$data['upload_path'] = '';
}
$growPage->update($data->all());
return redirect('growpage');
}
示例9: delete_attachment
public function delete_attachment($file_name, $entity = 'event', $entity_id = 0, $type = NULL)
{
$path = $entity . '/' . $entity_id . '/';
switch ($type) {
case 'group_photo':
$file_name = 'group_photo.jpg';
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_GROUP_PHOTO)->firstOrFail();
$path = $entity . '/' . $entity_id . '/';
$updated_file_name = 'group_photo-deleted-' . time() . '.jpg';
break;
case 'contract':
$file_name = 'contract.pdf';
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_CONTRACT_PHOTO)->firstOrFail();
$path = $entity . '/' . $entity_id . '/';
$updated_file_name = 'contract-deleted-' . time() . '.pdf';
break;
case 'schedule':
$file_name = 'schedule.pdf';
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_CONTRACT)->firstOrFail();
$path = $entity . '/' . $entity_id . '/';
$updated_file_name = 'schedule-deleted-' . time() . '.pdf';
break;
case 'evaluations':
$file_name = 'evaluations.pdf';
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_EVALUATION)->firstOrFail();
$path = $entity . '/' . $entity_id . '/';
$updated_file_name = 'evaluations-deleted-' . time() . '.pdf';
break;
case 'attachment':
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_CONTACT_ATTACHMENT)->firstOrFail();
$path = $entity . '/' . $entity_id . '/attachments/';
$file_extension = File::extension($path . $file_name);
$file_basename = File::name($path . $file_name);
$updated_file_name = $file_basename . '-deleted-' . time() . '.' . $file_extension;
break;
case 'avatar':
$attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_CONTACT_AVATAR)->firstOrFail();
$path = $entity . '/' . $entity_id . '/';
$updated_file_name = 'avatar-deleted-' . time() . '.png';
break;
default:
break;
}
if (!File::exists(storage_path() . '/app/' . $path . $file_name)) {
abort(404);
}
if (Storage::move($path . $file_name, $path . $updated_file_name)) {
$attachment->uri = $updated_file_name;
$attachment->save();
$attachment->delete();
}
return Redirect::action('RetreatsController@show', $entity_id);
}
示例10: function
});
Route::get('/images/temp/{image}', function ($image) {
if (!file_exists(storage_path("images/temp/{$image}"))) {
return response("Image not found on our servers!", 404);
}
return response()->download(storage_path("images/temp/{$image}"), null, [], '');
});
Route::post('/images/temp/save', function (Request $request) {
$url = $request->input('url', '');
$message = $request->input('message', '');
if (Storage::exists("images/temp/{$message}")) {
if (Storage::exists("images/{$message}")) {
//if a file with the same name exists in the main directory, simply delete the temp file
Storage::delete("images/temp/{$message}");
} else {
Storage::move("images/temp/{$message}", "images/{$message}");
}
\App\Image::create(['file_name' => $message, 'description' => $request->input('description', ""), 'alt' => $request->input('alt', "")]);
return response("Success");
} else {
return response("Error", 401);
}
});
// Authentication routes...
// Route::get('auth/login', 'Auth\AuthController@getLogin');
// Route::post('auth/login', 'Auth\AuthController@postLogin');
// Route::get('auth/logout', 'Auth\AuthController@getLogout');
//
// // Registration routes...
// Route::get('auth/register', 'Auth\AuthController@getRegister');
// Route::post('auth/register', 'Auth\AuthController@postRegister');
示例11: updateFilenameIfChanged
private function updateFilenameIfChanged($old, $new)
{
if ($this->filenameWasChanged($old, $new)) {
Storage::move('laramanager/images/' . $old, 'laramanager/images/' . $new);
}
}
示例12: edit
/**
* Edit user
*
* @param Request $request
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function edit(Request $request, $id)
{
$user = User::getUserById($id);
if (!empty($user)) {
if ($request->isMethod('post')) {
$rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'type' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username,' . $id, 'email' => 'required|email|unique:users,email,' . $id, 'pass' => 'min:6|max:12', 'pass_confirmation' => 'min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png'];
Validator::make($request->all(), $rules)->validate();
$user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name');
$user->position = $request->input('position');
$user->role_id = $request->input('type');
if ($request->has('phone')) {
$user->phone = $request->input('phone');
}
if (!empty($request->file("image"))) {
if (!empty($user->image)) {
if (Storage::exists('uploads/' . $user->image)) {
Storage::delete('uploads/' . $user->image);
}
}
$generated_string = str_random(32);
$file = $request->file("image")->store('uploads');
$new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('image'));
$img->crop(200, 200);
$img->save(storage_path('app/public/uploads/' . $new_file));
$user->image = $new_file;
}
$user->username = $request->input('username');
$user->email = $request->input('email');
$user->notification = $request->has('notification');
if ($request->has('pass')) {
$user->password = Hash::make($request->input('pass'));
}
$user->approve = 1;
$user->save();
$notifications = Notification::getNotificationBySenderId($user->id);
foreach ($notifications as $notification) {
$notification->delete();
}
$notifications = Notification::getNotificationByReaderId($user->id);
foreach ($notifications as $notification) {
$notification->delete();
}
if ($user->role_id == 1) {
$notification = new Notification();
$notification->from = 1;
$notification->to = $user->id;
$notification->type = 1;
$notification->save();
}
return redirect()->route('approved_users');
} else {
$user_roles = UserRole::getRoles();
return view('admin.user.edit', compact('user', 'user_roles'));
}
} else {
return redirect()->back();
}
}
示例13: merge
//.........这里部分代码省略.........
if (empty($contact->address_primary->city) && !empty($merge->address_primary->city)) {
$contact->address_primary->city = $merge->address_primary->city;
}
if (empty($contact->address_primary->state_province_id) && !empty($merge->address_primary->state_province_id)) {
$contact->address_primary->state_province_id = $merge->address_primary->state_province_id;
}
if (empty($contact->address_primary->postal_code) && !empty($merge->address_primary->postal_code)) {
$contact->address_primary->postal_code = $merge->address_primary->postal_code;
}
if (empty($contact->address_primary->country_code) && !empty($merge->address_primary->country_code)) {
$contact->address_primary->country_code = $merge->address_primary->country_code;
}
$contact->address_primary->save();
//emergency_contact_info
if (NULL === $contact->emergency_contact) {
$contact->emergency_contact = new \montserrat\EmergencyContact();
$contact->emergency_contact->contact_id = $contact->id;
}
if (empty($contact->emergency_contact->name) && !empty($merge->emergency_contact->name)) {
$contact->emergency_contact->name = $merge->emergency_contact->name;
}
if (empty($contact->emergency_contact->relationship) && !empty($merge->emergency_contact->relationship)) {
$contact->emergency_contact->relationship = $merge->emergency_contact->relationship;
}
if (empty($contact->emergency_contact->phone) && !empty($merge->emergency_contact->phone)) {
$contact->emergency_contact->phone = $merge->emergency_contact->phone;
}
if (empty($contact->emergency_contact->phone_alternate) && !empty($merge->emergency_contact->phone_alternate)) {
$contact->emergency_contact->phone_alternate = $merge->emergency_contact->phone_alternate;
}
$contact->emergency_contact->save();
//emails
foreach ($merge->emails as $email) {
$contact_email = \montserrat\Email::firstOrNew(['contact_id' => $contact->id, 'location_type_id' => $email->location_type_id]);
$contact_email->contact_id = $contact->id;
$contact_email->location_type_id = $email->location_type_id;
$contact_email->is_primary = $email->is_primary;
//only create or overwrite if the current email address for the location is empty
if (empty($contact_email->email)) {
$contact_email->email = $email->email;
$contact_email->save();
}
}
//phones
foreach ($merge->phones as $phone) {
$contact_phone = \montserrat\Phone::firstOrNew(['contact_id' => $contact->id, "location_type_id" => $phone->location_type_id, "phone_type" => $phone->phone_type]);
$contact_phone->contact_id = $contact->id;
$contact_phone->location_type_id = $phone->location_type_id;
$contact_phone->phone_type = $phone->phone_type;
$contact_phone->is_primary = $phone->is_primary;
//only create or overwrite if the current email address for the location is empty
if (empty($contact_phone->phone)) {
$contact_phone->phone = $phone->phone;
$contact_phone->save();
}
}
//notes - move all from merge to contact
foreach ($merge->notes as $note) {
$note->entity_id = $contact_id;
$note->save();
}
//groups - move all from merge to contact
foreach ($merge->groups as $group) {
$group_exist = \montserrat\GroupContact::whereContactId($contact_id)->whereGroupId($group->group_id)->first();
if (!isset($group_exist)) {
$group->contact_id = $contact_id;
$group->save();
}
}
//relationships
foreach ($merge->a_relationships as $a_relationship) {
$a_relationship_exist = \montserrat\Relationship::whereContactIdA($contact_id)->whereContactIdB($a_relationship->contact_id_b)->whereRelationshipTypeId($a_relationship->relationship_type_id)->first();
if (!isset($a_relationship_exist)) {
$a_relationship->contact_id_a = $contact_id;
$a_relationship->save();
}
}
foreach ($merge->b_relationships as $b_relationship) {
$b_relationship_exist = \montserrat\Relationship::whereContactIdB($contact_id)->whereContactIdA($b_relationship->contact_id_a)->whereRelationshipTypeId($b_relationship->relationship_type_id)->first();
if (!isset($b_relationship_exist)) {
$b_relationship->contact_id_b = $contact_id;
$b_relationship->save();
}
}
//touchpoints
foreach ($merge->touchpoints as $touchpoint) {
$touchpoint->person_id = $contact_id;
$touchpoint->save();
}
//attachments
foreach ($merge->attachments as $attachment) {
$path = 'contact/' . $merge_id . '/attachments/' . $attachment->uri;
$newpath = 'contact/' . $contact_id . '/attachments/' . $attachment->uri;
Storage::move($path, $newpath);
$attachment->entity_id = $contact->id;
$attachment->save();
}
}
return view('persons.merge', compact('contact', 'duplicates'));
}