JOHNMAC's avatar

image is not displaying in front-end while saving in destination folder

m working on ecommerce site, when i add product then it show on index page without image but image is saving in the destination folder, can anyone provide solution fot it,

code of ProductsController:

  public function productPreview(Request $request)
{
    $productsModel = new ProductsModel();
    $product = $productsModel->getProduct($request->id);
    if ($product == null) {
        abort(404);
    }

    $gallery = array();
    if ($product->folder != null) {
        $dir = '../storage/app/public/moreImagesFolders/' . $product->folder . '/';
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                $i = 0;
                while (($file = readdir($dh)) !== false) {
                    if (is_file($dir . $file)) {
                        $gallery[] = asset('storage/moreImagesFolders/' . $product->folder . '/' . $file);
                    }
                    $i++;
                }
                closedir($dh);
            }
        }
    }

    return view('publics.preview', [
        'product' => $product,
        'cartProducts' => $this->products,
        'head_title' => mb_strlen($product->name) > 70 ? str_limit($product->name, 70) : $product->name,
        'head_description' => mb_strlen($product->description) > 160 ? str_limit($product->description, 160) : $product->description,
        'gallery' => $gallery
    ]);
}
0 likes
4 replies
cipsas's avatar

I think your storage folder is not public

JOHNMAC's avatar

@CIPSAS - m storing into another folder, the actual path of the folder where the images are storing is: D:\xampp\htdocs\laravel\laraecom\storage\app\public\moreImagesFolders

cipsas's avatar

Can you check, what image path is display in frontend, which could not be found?

Please or to participate in this conversation.