1

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
15
  • just displaying it on local host Commented Aug 22, 2014 at 12:08
  • Show us the code you are using to display the image, and var_dump the image url Commented Aug 22, 2014 at 12:09
  • did you check your .htaccess file if there is one? Commented Aug 22, 2014 at 12:16
  • yes there is .htaccess file Commented Aug 22, 2014 at 12:19
  • 1
    What does {{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }} outputs ? Commented Aug 22, 2014 at 12:51

4 Answers 4

3
+50
  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> 
    
Sign up to request clarification or add additional context in comments.

2 Comments

It works the only problem that i facing is of .htaccess file code now it is working properly thanks @Fasil kk
my previous code was like this <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !­d RewriteCond %{REQUEST_FILENAME} !­f RewriteRule ^ index.php [L] </IfModule>
1

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)

2 Comments

yes the upload folder is in public itself but i think there is big issue of permission.
@alou , I think you are incorrect about the "Another thing" part, the capitalization is correct, Ubuntu just uses a funny font. However, I think your first point is spot on.
0

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.

3 Comments

i dis-agree for the path that you had given inHTML::image('/var/www/testLara/uploadImg/B05BgJ_school-uniform.jpg') because when we use HTML::image('') it takes path of out base url itself so there is no need to gave full path there unless it get invalid url
from your code it will generate html like this <img src="localhost/testLara/var/www/testLara/uploadImg/…"> and it is invalid for url
Oh, you're right, my mistake. Anyway, I think you should move uploadImage in /public directory. Also, on Ubuntu (and other Linux distros) uploadImg and uploadimg are two different directories. So rename you directory or change name in code.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.