Ricky
Ricky

Reputation: 384

issue in displaying Image in laravel4

I had uploaded an image by using the Intervention PHP image handling and manipulation library in laravel4. By using this library I uploaded the image properly but the problem I facing is that when I tryed to display those image from database, it is showing that there is an invalid url. However, the url is valid and I think this is an issue regarding permissions.

I am posting the below permission that is given by default to an uploading folder and also the user is permitted to access it is www-data.enter image description here

My Code

@section('main')
@extends('layouts/user')
<h1>All Users</h1>

<p>{{ link_to_route('users.create', 'Add new user') }}</p>

@if ($users->count())
    <table class="table table-striped">
        <thead>
            <tr>
                <th>FirstName</th>
                <th>LastName</th>
                <th>Email</th>
                <th>Address</th>
                <th>Image</th>
                <th>Action</th>
            </tr>
        </thead>

        <tbody>
            @foreach ($users as $user)
                <tr>
                    <td>{{ $user->firstName }}</td>
                    <td>{{ $user->lastName }}</td>
                    <td>{{ $user->emailId }}</td>

                    <td>{{ $user->address }}</td>
                    <td>{{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }}</td>

                    </td>

                    <td>{{ link_to_route('users.edit', 'Edit',
                            array($user->id), array('class' => 'btn btn-info')) }}</td>
                                                <td>
                                    {{ Form::open(array('method' 
                            => 'DELETE', 'route' => array('users.destroy', $user->id))) }}                       
                                                        {{ Form::submit('Delete', array('class'
                            => 'btn btn-danger')) }}
                        {{ Form::close() }}
                    </td>

                </tr>
            @endforeach
        </tbody>

    </table>
            <div class="pagination"><?php echo $users->links(); ?></div>
@else
    There are no users
@endif

@stop

Upvotes: 1

Views: 182

Answers (4)

Jeremy Anderson
Jeremy Anderson

Reputation: 825

Your "uploadImg" directory is not inside the "public" directory, as others have said, this is according to your screenshot. Is there another uploadImg directory inside "public"? There are three very important questions that remain unanswered.

  1. What path does your database show in the table?
  2. What does {{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }} output?
  3. Where is the actual image file located, once uploaded? (go check now)

Upvotes: 0

Fasil kk
Fasil kk

Reputation: 2187

  1. Check what error you are getting when you displaying the image from from browser directly.(I mean enter the full URL to the image on browser).

  2. Make sure the URL generated by laravel and the real image URL are same. if you can display the image from browser directly.

  3. All the images should be in public folder and normally should not have an .htacces file in the base.(I mean the folder below public)

  4. Make sure .htaccess ile in the public folder is like this,

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
    
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule> 
    

Upvotes: 3

alou
alou

Reputation: 1502

Any images you create / upload need to go after public/ (or whatever your public folder is) otherwise it will not render to a valid url, since the request will always be to path-to-public-folder/image-folder/image.jpg or something and according to the folder structure in your image, the image-folder is unreachable.

In your case, you created a folder uploadimg in the same level with app directory, while it should be at public/uploadimg

Another thing i notice is that you ask for an image from

 {{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }}

while it should be from

 {{ HTML::image('uploadimg/B05BgJ_school-uniform.jpg') }}

(assuming the image name and path is correct, this would work if the uploadimg folder is inside public/ folder)

Upvotes: 1

djm.im
djm.im

Reputation: 3323

The problem is, perhapse, path to the image. The root directory for laravel application is app/ directory.

Try to puth apsolute path: HTML::image('/var/www/testLara/uploadImg/B05BgJ_school-uniform.jpg').

And you should store your images in some subdirectory of /public directory.

Upvotes: 0

Related Questions