2
votes
  • Laravel Version: 8.35.1
  • PHP Version: 8.0.0

Description:

I'm uploading an image with laravel using this code:

$product_image = $request->file('product_image');
$product_image_extension = $product_image->extension();
$product_image_name = time() . '.' . $product_image_extension;
$product_image->storeAs('/media/product_images', $product_image_name);
$model->product_image = $product_image_name;

It works fine, the file is uploaded to storage/app/media/product_images/.

Then, I run the command

php artisan storage: link

to create the symlink in public. The Command Execute Like this:

Local NTFS volumes are required to complete the operation.
The [E:\Complete Programming Bootcamp\laravel Work\ecom-project\cyber_shopping\public\storage] link 
has been connected to [E:\Complete Programming Bootcamp\laravel Work\ecom- 
project\cyber_shopping\storage\app/public].
The links have been created.

I am Using This Code To Display Image:

{{asset('storage/media/product_images/' . $list->product_image)}}

But Image is not displaying on the frontend.

Also, The Storage Folder Is not created in the public folder. PLz, Help Me.

Thanks

2
try to access that image directly from browser, does the image accessible from that url?Localhousee
yes, I try this but the page not found error occurs. When I Copy the storage/app/public/[media(this folder)] paste it in the public/storage(created by myself) folder the images displayed. But This process is not dynamic. I need that when I upload an image it also stores in the public/storage folder and the display.msaad dev
Try this rm -rf public/storage Then run php artisan storage:linkHedayatullah Sarwary
I try this, but it does not work for me.msaad dev
You have to store the files under storage/app/public/media/product_images/ to make them publicly accessibles through asset('storage/media/product_images/' . $list->product_image). So change $product_image->storeAs('/media/product_images', $product_image_name); to ` $product_image->storeAs('public/media/product_images', $product_image_name);`porloscerros Ψ

2 Answers

2
votes

Step 1:: Store Image

$path = ‘’;
if( $request->has('product_image') ) {
    $path = $request->file('product_image')->store('media/product_images');
}
$model->product_image = $path;

Step 2:: Check Store File Path

The File Will Be Store In Path::

————————————————————————————————

Storage/app/public/media/product_images/

Step 3:: Link Storage In Public Folder

Run The Storage Link Command and remove storage link folder from the public if already exist

php artisan storage:link

Step 4:: Create Global Function To Access Images Main Controller.php File Create Global Storage Image Getting Function Like This

public static function getUrl($path)
{
    $url = "";
    if( !empty($path) && Storage::disk('public')->exists($path) )
        $url = Storage::url($path);
    return $url;
}

Step 5:: Use Function In Assest To Display Image

<img src="{{ getUrl($list->product_image) }}" />
1
votes

According to https://github.com/photoncms/cms/issues/8, you are trying to symlink on fat32 drive on which it does not work. Try to test it on NTFS drive