mardi 11 mai 2021

Display image from Laravel to Html

How can I retreive image from laravel to plain HTML: Both laravel and HTMl running in different port Laravel Controller:

 public function imageUpload(Request $request)
    {
        $allowedfileExtension=['jpg','png','jpeg'];
        $file = $request->file('fileName');
        $extension = $file->getClientOriginalExtension();
        $check = in_array($extension,$allowedfileExtension);
        if($check) {
            $file=$request->fileName ;
            $path = $file->store('public/images');
            $name = $file->getClientOriginalName();

            return response()->json([
                'message' => $path,
                'Filevalidation'=>True
            ],200);

        } else {
            return response()->json([
                'message' => "Invalid File Extension",
                'Filevalidation'=>True
            ]);
        }

    }

Images are stored in storage/app/public/images/ScTZ2rhj26sdJT3la5TKKsZ1DPbnbNl1YDuC3JrS.jpg (This path)

Html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>Hello</h1>
    <img
      src="http://127.0.0.1:8000/public/images/C7o2dEHLlZLyP7RJewuiRsC4DiQ4oAyDxmPmJrsb.jpg"
      alt=""
    />
  </body>
</html>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire