Image is not displaying in the nav bar after uploading it to the database. I think there is something wrong with the file storage path, but I don't know where I am making a mistake.
This is the image storage path
$image = $request->file('picture')
$path = $image->store('public/images');
$yourModel = new User();
$yourModel->name = $validateData['name'];
$yourModel->email = $validateData['email'];
$yourModel->password = $validateData['password'];
$yourModel->image = $path;
you store the image in the public iamges and in blade you say show the iamge form the storage/images that is incorrect you need to change the ima html to <img class="" src="{{ asset('images/' . Auth::user()->image) }}">
Related
I wrote a code to upload an image file and that is already working, I also can save the image url in my database. The problem is the image is not loaded permanently. Which means I can see the image after I uploaded it, but the moment I save it, the url is not valid anymore. Does anyone know how to fix it? I mean store the image permanetly on my project. I want users to upload and use their own images? Thank you for youre help.
uploading in template
<input style="margin-left: 35px" type="file" #change="onFileChange" />
Displaying the image
<img v-if="data.image" :src="data.image" style="max-width:450px;vertical-align:middle;margin:0px 5px 5px"/>
script method
onFileChange()e {
const file = e.target.files[0];
this.data.image = URL.createObjectURL(file);
},```
You could do something like this in your Controller:
$request->validate([
'image' => 'required|image|mimes:jpeg,jpg,png,gif|max:2048',
]);
$imageName = time().'.'.$request->image->extension(); //What you store in DB
$request->image->move(public_path('images'), $imageName); //Put the image in a public folder
And from there you could access it via URL.
I am saving an uploaded image like this:
$profile_picture = $request->file('profile_picture');
$user->profile_picture = $profile_picture->getClientOriginalName();
Storage::disk('public')->put( $user->profile_picture, $request->file('profile_picture') );
and then I am trying to display that image in HTML with:
<img class="img-fluid" src="{{ asset('storage/'. Auth::user()->profile_picture) }}">
the image is being saved in storage/app/public, but the image is not showing in html, how do i go about this?
thank you
You may use response method on a Laravel filesystem
return Storage::disk('public')->response($user->profile_picture);
N.B: In order to do that, you need a Laravel route. The above code should be located in a controller method
I have a form include image, this image i get from webcam and store it to img tag, how can i save data from attribute src, usually to store file using upload file.
<img id="myImage" src="data:image/png;base64,IvBo9Vraf...." alt="image from snapshot" />
I have read similar questions but not as i expected
With this code you can saved the files.
$filename = $request->file('myFile')->store('files');
$data= new FileModel();
$data->file = $filename;
$data->save();
or you can try below method
$myImage = $request->file('myFile');
if(!in_array($myImage->getMimeType(), ['image/jpeg', 'image/png'])){
abort(500, 'Unsupported Image Type');
}
$imageName = str_replace('myImages/', '', $myImage->store('myFile'));
return ['my_image'=>$profile_picture_name];
Im currently using barryvdh/laravel-snappy to convert my data to pdf format.
The code i'm using is :
public function generate_pdf($id){
$rfq = RFQ::find($id);
$data = array(
'rfq' => $rfq,
);
//return view('rfq.pdf')->with('rfq', $rfq);
$pdf = PDF::loadView('rfq.pdf',$data)->setPaper('a4')->setOption('margin-bottom', 0);
return $pdf->download($rfq->rfq_no.'-'.date_timestamp_get(date_create()).'.pdf');
}
And then, I have to add an image to the pdf file. So i have to add this line to the pdf.blade.php file.
<img src="{{ asset('img/logo.png') }}">
But then, the image isn't showing properly.
It's visible, but it's OPACITY is very low, around 0.2.
But when viewing the actual image file, and the one in the actual html template, everything's good.
I tried <img src="data:image/png;base64,{{ base64_encode(#file_get_contents(asset('img/logo.png'))) }}">
but still, it's the same.
Whenever I open an item the link would be
http://localhost/mywebsite/public/item/{$item_id}
the avatar will break. Below is the code I used
<img src="uploads/avatars/{{ Auth::user()->avatar }}">
The location of the image is C:\xampp\htdocs\mywebsite\public\uploads\avatars
I presume that as you are using relative URLs the translated path in browser will be http://localhost/mywebsite/public/item/{$item_id}/uploads/avatars/{{ Auth::user()->avatar }}
And that's not what you want
Try
<img src="http://localhost/mywebsite/public/uploads/avatars/{{ Auth::user()->avatar }}">
In production in will be just
<img src="/uploads/avatars/{{ Auth::user()->avatar }}">
Am not sure it will work on xampp though
So to say, I recommend using Laravel Valet or Homestead instead of Xampp, it cuts some problems like yours off.
in File model i created a function to get file encoded base64
public function getFile()
{
$path = storage_path('app'). "/" . $this->path;
$type = File::mimeType($path);
$file = Storage::disk('local')->get("/". $this->path);
return "data:image/png;base64,".base64_encode($file);
}
in blade You can use like that
<img src = '$file->getFile()'>