Images not displaying in webpage interface while it was fine and displayed in localhost.
I made an app with Laravel 5.2 and it was correct in localhost but after updaing it online we faced a very bad problem. All images which come from database aren't showing in webpage interface. I am storing images in Laravel root directory storage folder and image links to database table. Each image gets the exact stored image URL value but is not displaying properly. Also when I copied the image URL and pasted it in my browser it said :
Whoops, looks like something went wrong
I am accessing images via this method
<img src="{{url::to('mvimage/'.$image->image) }}" />
I am accessing image via route.php by using this method
Route::get('mvimage/{file_name}', function($filename){
$path = storage_path('app').'\mvimage\\'.$filename;
$image = \File::get($path);
$mime = \File::mimeType($path);
return \Response::make($image, 200)->header('Content-Type', $mime);
});
I think the problem comes from the back slash..
Try with this
storage_path("app/mvimage/$filename");
Note :
In your view you should access the facade with URL not url
In your route file, you should be on the root namespace so no need for \ before File and Response
Related
Hello Folks, I hope you guys are well.
Last week I am getting an issue in my Laravel Application which is regarding the S3 bucket.
Files, Images and PDF are not getting store in my S3 Bucket. The code which I have written is working fine for me for last 10 months in production environment.
Then I checked that code in my local machine which is (localhost) and that is working fine. Then I clear my Laravel Application its Cache , Views , Routes , Config. Also, checked my .env file which is same as local environment.
The last thing which I can do is check the incognito mode after clearing all the cache routes and other things. In incognito mode my files are getting uploaded for the production site but when I upload that image from the normal window its showing me the get file content error.
I am giving you the screenshots and the code which I am using let me know if you can help me with this and yes I know the problem is very strange.
My Controller Function
public function saveAboutBannerSlide(Request $request){
$banner_tile = $request->banner_title;
$banner_des = $request->banner_des;
//Getting File name form the form
$file = $request->file('banner_image');
//S3 OBJECT
$s3 = Storage::disk('s3');
$new = uniqid() . "_banner";
//Uploading With the New Name
$upload_path = 'uploads/manage-cms/aboutus-images/' . $new;
//Put File in S3 Bucket
$s3->put($upload_path, file_get_contents($file));
//Getting URL OF THE Image
$up_img = $s3->url($upload_path);
}
Error image while uploading image
What is the correct way to upload,update and get an image or file in laravel ? I had gone through laravel docs and other references but its confusing.Can anyone show a complete simple example for
any disk configuration in filesystems.php
a simple method to upload and update image in controller
and what will be the image full url?
input type file name is image you can store directly into images folder
return $path = $request->image->store('images');
I have an issue with a view and generated content to produce a PDF. At the moment, I've been working with niklasravnsborg\LaravelPdf (a wrapper for mPDF, because of an issue with another PDF writer I was working with beforehand), which turns out nice PDFs that are of the quality that I want.
I have never had an issue with images inside of the view before with this PDF writer though, but I must admit that they were with images that had been set-up inside the view already (like a logo, rather than say an employees photo).
My issue arises in a way that has at least allowed me to track down the issue a little better.
From my controller, I get the following:
$employeeMedCert = $employee->attachments()->where('category','Medical Examiners Certificate')->orderBy('endDate','desc')->limit(1)->get();
And then in my blade I have the following:
#foreach($employeeMedCert as $med){
{{Storage::url($med->attachment)}}
#endforeach
Now, with this current setup, I get the public path of the attachment, without any issue at all.
However, if I do the following:
#foreach($employeeMedCert as $med){
<img src="{{Storage::url($med->attachment)}}">
#endforeach
It stalls my Laravel to a point where I have to reset the server and hasn't generated anything.
I'm not sure what the issue is, like I said, I've had no issues with images before and the images I am referencing dynamically aren't large by any means (300 - 600 kB), so I am not sure where the issue actually is.
Upload controller action:
$path = Storage::putFile('public/employees', new File(request('file')));
employeeAttachment::create([
'attachment' => $path,
'attachmentType' => Storage::mimeType($path),
'category' => $request->type,
'endDate' => $request->dueDate,
'date' => $request->date,
'employeeID' => $employee,
'createdBy' => Auth::id()
]);
The big clue for this problem is that in html <img> tags do a get request when they are run in html. This means you could be having a permission error.
You can check this by opening your devtools in chrome and checking out your server requests in any website that has an image tag.
Following things to check (assuming you are using a basic storage e.g. not using AWS):
Is image in your public folder or have you correctly created your sym link: https://laravel.com/docs/5.6/filesystem.
If your files are public can you navigate to it in the browser?
Have you tried using the url instead of going through storage? e.g. <img src="{{base_url() . $med->attachment)}}"> (assuming $med->attachment is a file path).
Assuming it's a public file you shouldn't have to go through the Storage facade to access it. Let me know if this points you in the right direction.
The purpose of the Storage facade is to save files and get files and load them into a php variable. Currently you are loading the file from the server and then pointing your image tag to the file and not to the url of where the image is stored.
Putting in a valid url into the img tag should solve your problem (shown in 3 above).
Have tried the API call as listed on Podio dev site to upload a file and I am not getting much joy.
I am trying to "Upload a file" in the first instance using the POST operation and passing the json with the source url to the endpoint as specified.
I can use other methods just fine but since there is little in the way or error feedback I am stuck I keep getting error 404
I have used - https://developers.podio.com/doc/files/upload-file-1004361
(have tried both GET & POST)
image of method with error i get
Upload file method that you are trying to use (https://developers.podio.com/doc/files/upload-file-1004361) is expecting file path which is supposed to be local file but not url.
Here is example of how it should be used:
http://podio.github.io/podio-php/api-requests/
$file = PodioFile::upload($path_to_file, $filename_to_display);
print 'File uploaded. The file id is: '.$file->id;
Here is another example on how to work with files:
https://developers.podio.com/examples/files
I'm using GAE version 1.9.0 and I want to delete an image from the data storage and upload another image to its location. This is how I'm doing it right now.
unlink("gs://my_storage/images/test.jpg");
move_uploaded_file($_FILES['image']['tmp_name'],'gs://my_storage/images/test.jpg');
And then I want to get the Image serving URL of the latest uploaded image, and I do it like this.
$image_link = CloudStorageTools::getImageServingUrl("gs://my_storage/images/test.jpg");
The issue is, when the name of the deleted image("test.jpg") and the uploaded image("test.jpg") is the same, the old file is served when I call for the newly uploaded file(I think it is cached.)
Is there anyway I can permanently delete this file without caching it?
You should probably delete the original serving URL before creating another with the same name.
There's a deleteImageServingUrl() method in CloudStorageTools that you can use to do this.
Here it is how to do in php laravel.
$object = $post_media->media_cloud;
$objectname = substr($object,48,100);
$bucket = Storage::disk('gcs')->delete($objectname);
Here in $object i get google cloud image url from db
Then we take only object name from that url, by substr.
Since you have given in your config Storage class as Storage::disk('gcs')
so this will call the function delete by taking the objectname.
Hope it helps anyone.
Note : For multiple images either pass an array of objects, or repeat it foreach loop.