Laravel Intervention Saving Image in a specific disk












3














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.










share|improve this question



























    3














    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.










    share|improve this question

























      3












      3








      3







      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 26 '17 at 0:19









      kurtfoster

      13110




      13110
























          2 Answers
          2






          active

          oldest

          votes


















          0














          $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.





          share|improve this answer





















          • Not work for me.
            – fzyzcjy
            Jul 18 '17 at 7:32



















          0














          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());





          share|improve this answer





















            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            0














            $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.





            share|improve this answer





















            • Not work for me.
              – fzyzcjy
              Jul 18 '17 at 7:32
















            0














            $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.





            share|improve this answer





















            • Not work for me.
              – fzyzcjy
              Jul 18 '17 at 7:32














            0












            0








            0






            $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.





            share|improve this answer












            $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.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 26 '17 at 1:21









            Jon Awoyele

            445




            445












            • 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




            Not work for me.
            – fzyzcjy
            Jul 18 '17 at 7:32













            0














            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());





            share|improve this answer


























              0














              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());





              share|improve this answer
























                0












                0








                0






                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());





                share|improve this answer












                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());






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 16:59









                Nazalas

                82




                82






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'