Laravel Intervention Saving Image in a specific disk
I'm trying to use Intervention to resize an image, then save it in a disk that I've defined, but I can't get it to work. Using public_folder is saving it in a folder in the root of my app called /public.
I've created a new disk
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'visibility' => 'public',
],
And I need to accept input from the user, then save their uploaded file to that disk, then the filepath to the db.
$fieldFile = $request->file($fieldName);
$imageName = time();
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension());
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension();
I'd like to end up with something similar to what should happen from
$fieldValue = $fieldFile->store($fieldName, 'images');
The file should end up at
/path/to/laravel/storage/app/public/images/
Later, if I change the images disk to s3 or somewhere else, I'd like this code to continue to function.
php image laravel-5.3 intervention
add a comment |
I'm trying to use Intervention to resize an image, then save it in a disk that I've defined, but I can't get it to work. Using public_folder is saving it in a folder in the root of my app called /public.
I've created a new disk
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'visibility' => 'public',
],
And I need to accept input from the user, then save their uploaded file to that disk, then the filepath to the db.
$fieldFile = $request->file($fieldName);
$imageName = time();
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension());
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension();
I'd like to end up with something similar to what should happen from
$fieldValue = $fieldFile->store($fieldName, 'images');
The file should end up at
/path/to/laravel/storage/app/public/images/
Later, if I change the images disk to s3 or somewhere else, I'd like this code to continue to function.
php image laravel-5.3 intervention
add a comment |
I'm trying to use Intervention to resize an image, then save it in a disk that I've defined, but I can't get it to work. Using public_folder is saving it in a folder in the root of my app called /public.
I've created a new disk
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'visibility' => 'public',
],
And I need to accept input from the user, then save their uploaded file to that disk, then the filepath to the db.
$fieldFile = $request->file($fieldName);
$imageName = time();
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension());
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension();
I'd like to end up with something similar to what should happen from
$fieldValue = $fieldFile->store($fieldName, 'images');
The file should end up at
/path/to/laravel/storage/app/public/images/
Later, if I change the images disk to s3 or somewhere else, I'd like this code to continue to function.
php image laravel-5.3 intervention
I'm trying to use Intervention to resize an image, then save it in a disk that I've defined, but I can't get it to work. Using public_folder is saving it in a folder in the root of my app called /public.
I've created a new disk
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'visibility' => 'public',
],
And I need to accept input from the user, then save their uploaded file to that disk, then the filepath to the db.
$fieldFile = $request->file($fieldName);
$imageName = time();
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension());
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension();
I'd like to end up with something similar to what should happen from
$fieldValue = $fieldFile->store($fieldName, 'images');
The file should end up at
/path/to/laravel/storage/app/public/images/
Later, if I change the images disk to s3 or somewhere else, I'd like this code to continue to function.
php image laravel-5.3 intervention
php image laravel-5.3 intervention
asked Feb 26 '17 at 0:19
kurtfoster
13110
13110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$fieldFile = $request->file($fieldName);
//$imageName = time();
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
$location = Storage::disk('images')->put($imageName, $image);
//images can be substituted for any disk local or s3 etc.
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
add a comment |
You need to encode the image like so
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42463274%2flaravel-intervention-saving-image-in-a-specific-disk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$fieldFile = $request->file($fieldName);
//$imageName = time();
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
$location = Storage::disk('images')->put($imageName, $image);
//images can be substituted for any disk local or s3 etc.
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
add a comment |
$fieldFile = $request->file($fieldName);
//$imageName = time();
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
$location = Storage::disk('images')->put($imageName, $image);
//images can be substituted for any disk local or s3 etc.
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
add a comment |
$fieldFile = $request->file($fieldName);
//$imageName = time();
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
$location = Storage::disk('images')->put($imageName, $image);
//images can be substituted for any disk local or s3 etc.
$fieldFile = $request->file($fieldName);
//$imageName = time();
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
$location = Storage::disk('images')->put($imageName, $image);
//images can be substituted for any disk local or s3 etc.
answered Feb 26 '17 at 1:21
Jon Awoyele
445
445
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
add a comment |
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
Not work for me.
– fzyzcjy
Jul 18 '17 at 7:32
add a comment |
You need to encode the image like so
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
add a comment |
You need to encode the image like so
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
add a comment |
You need to encode the image like so
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
You need to encode the image like so
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
answered Nov 21 '18 at 16:59
Nazalas
82
82
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42463274%2flaravel-intervention-saving-image-in-a-specific-disk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown