I
I
Ivan Lykov2018-12-21 21:52:37
Laravel
Ivan Lykov, 2018-12-21 21:52:37

Why is the picture saved as a folder?

Good day, I have a question.
Uploading a picture to the server means this way

if( $blog -> save() )
      {
        mkdir( "upload_for_post/" . $blog -> id, 0777 );
        if( $request -> hasFile( 'image' ) )
        {
          $file             = $request -> file( 'image' );
          $input[ 'image' ] = $file -> getClientOriginalName();
//					dd($input[ 'image' ]);
          $file -> move( public_path() . '/upload_for_post/' . $blog -> id . '/' . $input[ 'image' ] );
        }
        if( $validator -> fails() )
        {
          return redirect() -> route( 'posts' ) -> withErrors( $validator ) -> withInput();
        }
        return redirect() -> route( 'posts' ) -> with( 'status', 'Post added' );
      }

I save the picture in the created folder under the post after creating the post itself.
Everything would be fine, but in the end I get this picture
5c1d361af0ffd640006182.png
. The picture is saved as a folder .... how to deal with it. I have not come across anything like this before ... I will be glad for any practical advice and not a tomato, as it usually happens here

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Lykov, 2018-12-21
@Jhon_Light

The magic lies right here
Must be specified before$input[ 'image' ]" , "" . "

P
Pavel, 2018-12-21
@PavelMonro

Saved as a file with no extension, so set the extension

$file -> move( public_path() . '/upload_for_post/' . $blog -> id . '/' . $input[ 'image' ] . '.jpg');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question