1
votes

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);
});
1
Please check your error logs first and include any relevant error messages. There could be a number of reasons for a generic 500 error.Sherif
[2016-08-13 04:35:16] production.ERROR: exception 'Illuminate\Contracts\Filesystem\FileNotFoundException' with message 'File does not exist at path /home/techubaf/public_html/local/storage/app\teampics\2016-08-04-10-02-00am437.JPG' in /home/techubaf/public_html/local/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:41 Stack trace: this is the logger valueHanif Formoly
the problem is that if we want to access a photo publicly so we have to store it in public folder. but i am storing photos in storage folder and laravel does't allow me to access it. actually the file exist in the position it pointsHanif Formoly

1 Answers

1
votes

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