Problem showing an image in a laravel website - laravel

I save images in a controller with the $imagePath = "/upload/images/{$adver} address. Then these images are saved in a public folder in the root folder, but when I move these images file into the C-Panel I can't see them.
The address of an image is saved in advertise table and the images are saved in the public folder. I use src="advertise.image1" to show an image.
The images are in a database and I get the route to database to show them on the website.

Are you using the public_path helper function?
$imagePath = public_path("/upload/images/{$adver}");
You may have issues with your public path if you're saying they're not working on the remote location. Is your remote public path set as public_html rather than public?

Related

Storage laravel. Is this secure to keep private image?

Hi i'm working on sell picture project. I want to secure image in public folder . I follow this way How to protect image from public view in Laravel 5?
Everything work fine. I just want to make sure in storage Path thier is no way to access with URL right? I put my image into storage/images not storage/app/public
If i storage link it will be effect to my private image or not thanks
In Laravel the root of the webserver is the public directory and the entrypoint is public/index.php.
This means that you can access via web server everything under public directory (like javascript/css files and image assets).
The storage directory is one level up and there is no way to access it.
In the discussion you mention the url http://www.somedomainname.net/images/users/userImage.jpg refers to the file userImage.jpg under /your/document/root/laravel/app/public/images/users by default, so the storage directory is not even read.
Laravel, though, will let you link the storage/app/public directory inside the public/storage directory, using the command php artisan storage:link, but that's it.

Accessing Images to show in Blade Outside the public folder in laravel

I have some images in storage/app/uploads which i want to show on front end. Let Say blade file. But we have acces to public folder only in laravel and images ar in storage folder as i mentioned above so how i couls acces it so i colud set the src='?' in image tag to see image.

Cannot save and access images (Laravel)

I am having a problem with accessing images.
I can upload and receive an image to the database no problem; however, I have my images manually saved under the public/avatar folder and I can retrieve the images from that location by using:
{{ asset('/uploads/avatars/image.jpg }}
I cannot figure out how to save to that location; I've tried the following to no avail:
Storage::disk('local')->put('/uploads/avatars/', $image);
Also, when I try to save from the controller it saves everything in storage/app/public, but I don't know how to access the image files from the model nor how to save them somewhere else.
When you use this
Storage::disk('local')->put('/uploads/avatars/', $image);
then all of your images are store in storage/app/uploads/avatars directory. so you can not access it from public directory. If you want to access it from public directory, you have to make a symbolic link of storage/app/uploads/avatars in public directory. I think it work fine :)

how and where can store images with laravel?

how and where I can store images using laravel?
context:
I want display some images in my main view (these are predefined by me).
I also want to store images uploaded by users, however, do not know where to store these images.
I'd like to call these from the view...
Thank you very much for the help. :)
Basically you can save your files wherever you want within your Laravel application provided that you have permissions to create directory and file.
But I prefer saving files in the storage/app folder. Laravel provides a simple API to manipulate files on disk. See the docs.
Update:
This answer was posted when Laravel was in version 5.2.
From version 5.3 on, you can easily create symbolic links by running the artisan command php artisan storage:link. See the docs.
Make directory for images in myapp/public/images and keep images on there.
<img src="{{URL('/images/logo.jpg')}}">
If you want to display them on your site store them in your public directory. Since they are uploaded by users you will need to pass them through a form. Here is an example of a controller.
$file = Input::file('picture');
$file->move(public_path().'/images/',$user->id.'.jpg');
The user will submit a form with a picture field. The two lines above will store it in the public directory in an images folder, with the relevant user's id as its name. Your probably best off making a model in your database for images and their paths. If you do, add these lines after the two above.
$image = new Image;
$image->path='/images/'.$user->id.'.jpg';
$image->user_id = $user->id;
$image->save();
To display it in the view simply set an $image variable to the correct image model in your controller and pass it to the view. Then pop its path in the src of the image.
<img src={{$image->path}} alt={{$image->path}}>

laravel - image upload and display issues

I have a blog post application where I am uploading files to be displayed along with the post itself. I can successfully upload the image but I am unable to display it .
Here is how I am uploading it to a folder within my application..
and here is how i am displaying it..
I am uploading the image to the uploads folder under my public folder. and I am storing the image in the database as follows..
Although I can see that the image path is correct. I did an echo of the path that is being generated and the path to the image is correct.
Can you please let me know if there is something that I am doing wrong.
thanks
Change
$file = $file->move(public_path() . '/images/uploads', $filename);
to
$file = $file->move('images/uploads', $filename);
the above code will upload the picture to the public_path/images/uploads.
In your code, i can see you have used full physical path of your image directory to display the picture. Physical path only needed when you are going to upload an image.
try the following:
<img class="img-responsive" src="/images/uploads/{{ $post->thumbnail }}" >
You are storing the thumbnail within the post model, but are trying to fetch it form the blog model. Try $blog->post->thumbnail instead. (If you have set a relationship)

Resources