skip to Main Content

I’ve read through many tutorials and it still isn’t working. I’ve added a sym link but it still doesn’t save or show the image correctly. Can someone tell me the process of the following:

I want to upload an image to the folder storage/app/profilephotos/. It will be called whatever thhe hasname of the image is.
Then I want to be able to view the image via the url on the website.

to test, I created this sym link:

    public_path('storage/profilephotos') => storage_path('app/public/profilephotos')

When uploading an image I did this:

     Storage::put('profilephotos', $theimagefile);  

This uploaded the image to the following directory:

      c:myprojectstorageappprofilephotos

The name of the file is for example 12345.jpg.
Now I want to view the iamge on a web apge. In blade I tried to add this but it doesn’t work:

      asset('storage/profilephotos/12345.jpg')

I’ve already run storage:link which said:

      The [C:myprojectpublicstorage] link has been connected to [C:myprojectstorageapp/public].

I don’t know what else to do, can someone help?

thanks

2

Answers


  1. I think if your code is correct to upload image,then you are using linux based operating system,ubuntu,parrotos,kali-linux etc. may be permission issue, correct the permission of the folder /storage, set min 755.
    And also set user of the project folder www-data or at least /storage folder.

    Laravel basic code to upload image

    if ($request->hasFile('image_name')) {
        $imageName = time().'.'.$request->image_name->extension();
        $doctor->image_name=  $imageName;
        $request->image_name->storeAs('profilephotos', $imageName,'public');
    }
    

    Image store at /storage/profilephotos/image_name.png ,you can access image after creating the softlink as

     <img src="{{asset('/storage/profilephotos/image_name.png')}}"  alt="">
    

    And also first delete the already created softlink in /public folder, create again using command:

    php artisan storage:link
    

    Follow above step to upload and view image in laravel.

    Login or Signup to reply.
  2. public function image_save($images, $folderName, $name)
        {
            if ($images) {
                // Set the path where images will be saved
                $path = public_path('images/' . $folderName);
    
                // Create the directory if it doesn't exist
                if (!file_exists($path)) {
    
                    mkdir($path, 0777, true);
                }
                $imageName = 'XX' . '_' . $name . '.' . $images->getClientOriginalExtension();
                $images->move($path, $imageName);
            }
            return $imageName;
        }
    

    This May Help..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search