To display an image it has to be in the public folder, for example public/uploads/img.
Make sure that the privilages/ownership of the /uploads/img folder is configured in a way that allows the server to create new files in that folder.
When uploading files, you have to set the 'files' option to true when opening the form.
Move the uploaded file to the desired folder in the public directory. Give it a unique name (you don't want conflicts to happen).
Save the name you gave to the file in the database.
Display the image with
<img src="{{ public_path().'/uploads/img/'.$filename }}" />
where $filename is retreived from the database.
Thank you for the response,
I save the image directy to the database by having changed the User model.
Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('surname'); $table->string('email')->unique(); $table->string('password', 60); $table->string('type'); $table->binary('photo')->nullable(); $table->rememberToken(); $table->timestamps(); });
Laravel creates a blob 64kb field in the database which I've manually changed to mediumBlob for having more space.
I think I'll do it your way but how can I save it without having to change the model?
If you wil display the pictures on your site, it is much better that you do it my way.
Maybe there is a way to save a string as binary. Not sure. If it so imprtant not to change the database schema, you could probably also use the 'created_at' time as name for the file.
It would be even easier to name the saved image according to the user id, e.g. 'u_1324.jpg'.
Thanks for your help I'm getting closer each time.
I've now managed with the help of a tutorial but applying it to my app to save the files into the storage/app directory.
It stores the file every time with a diferent name.
It saves in the database the mime type, original filename and the filename which is different every time
I store it with Storage::disk('local'), but I would like it to be stored somewhere else for example as you say at
uploads/img because I get the problem of not being able to acces the storage/app directory when having my apache
pointing at the public directory as they are at the same level and the src route can't be absolute so I'm now pointing
at the route of the project and going src="../storage/app/{{ $user->filename }}
Take a look at how i wrote this library. You can use it if you want :). https://github.com/astroanu/laravel-image-cache
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community