Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel4中显示图像的问题_Php_Laravel 4 - Fatal编程技术网

Php 在laravel4中显示图像的问题

Php 在laravel4中显示图像的问题,php,laravel-4,Php,Laravel 4,我使用laravel4中的InterventionPHP图像处理和操作库上传了一幅图像。通过使用这个库,我正确地上传了图像,但我面临的问题是,当我试图从数据库中显示这些图像时,它显示有一个无效的url。但是,url是有效的,我认为这是关于权限的问题 我发布以下权限,这是默认情况下给一个上传文件夹,也允许用户访问它是www数据 我的代码 @section('main') @extends('layouts/user') <h1>All Users</h1> <p&g

我使用
laravel4
中的
Intervention
PHP图像处理和操作库上传了一幅图像。通过使用这个库,我正确地上传了图像,但我面临的问题是,当我试图从数据库中显示这些图像时,它显示有一个无效的url。但是,url是有效的,我认为这是关于权限的问题

我发布以下权限,这是默认情况下给一个上传文件夹,也允许用户访问它是www数据

我的代码

@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
@节('main')
@扩展('布局/用户')
所有用户
{{link_to_route('users.create','addnewuser')}

@如果($users->count()) 名字 姓氏 电子邮件 地址 形象 行动 @foreach($users作为$user) {{$user->firstName} {{$user->lastName} {{$user->emailId} {{$user->address} {{HTML::image('uploadImg/B05BgJ_school-uniform.jpg')} {{link_to_route('users.edit','edit',', 数组($user->id),数组('class'=>'btn btn info'))} {{Form::open(数组('method' =>'DELETE','route'=>array('users.destroy',$user->id))} {{Form::submit('Delete',array('class' =>'btn btn danger'))} {{Form::close()}} @endforeach @否则 没有用户 @恩迪夫 @停止
问题可能是图像的路径。 laravel应用程序的根目录是app/directory

尝试计算绝对路径:
HTML::image('/var/www/testLara/uploadImg/B05BgJ_school-uniform.jpg')


您应该将图像存储在
/public
目录的某个子目录中

问题可能是图像的路径。 laravel应用程序的根目录是app/directory

尝试计算绝对路径:
HTML::image('/var/www/testLara/uploadImg/B05BgJ_school-uniform.jpg')


您应该将图像存储在
/public
目录的某个子目录中

您创建/上传的任何图像都需要转到public/(或任何您的公用文件夹)之后,否则它将不会呈现为有效的url,因为请求将始终指向public folder/image folder/image.jpg或其他路径,并且根据图像中的文件夹结构,无法访问图像文件夹

在本例中,您创建了一个与app directory处于同一级别的文件夹uploadimg,而它应该位于public/uploadimg

我注意到的另一件事是,您要求从

 {{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }}
而它应该是从

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

(假设图像名称和路径正确,如果uploadimg文件夹位于public/folder中,则此操作有效)

您创建/上载的任何图像都需要位于public/(或任何您的公用文件夹)之后,否则它将无法呈现为有效的url,由于请求总是指向公用文件夹/image folder/image.jpg或其他内容的路径,并且根据图像中的文件夹结构,图像文件夹无法访问

在本例中,您创建了一个与app directory处于同一级别的文件夹uploadimg,而它应该位于public/uploadimg

我注意到的另一件事是,您要求从

 {{ HTML::image('uploadImg/B05BgJ_school-uniform.jpg') }}
而它应该是从

 {{ HTML::image('uploadimg/B05BgJ_school-uniform.jpg') }}
(假设图像名称和路径正确,如果uploadimg文件夹位于public/folder中,则此操作有效)

  • 检查直接从浏览器显示图像时出现的错误。(我的意思是在浏览器上输入图像的完整URL)

  • 确保laravel生成的URL与真实图像URL相同。如果可以直接从浏览器显示图像

  • 所有图像都应该在公用文件夹中,并且通常不应该在基础中有.htacces文件。(我指的是公用文件夹下面的文件夹)

  • 确保公用文件夹中的.htaccess文件如下所示

        <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> 
    
    
    选项-多视图
    重新启动发动机
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(+)/$http://%{http_HOST}/$1[R=301,L]
    重写cond%{REQUEST_FILENAME}-F
    重写规则^index.php[L]
    
  • 检查直接从浏览器显示图像时出现的错误。(我的意思是在浏览器上输入图像的完整URL)

  • 确保laravel生成的URL与真实图像URL相同。如果可以直接从浏览器显示图像

  • 所有图像都应该在公用文件夹中,并且通常不应该在基础中有.htacces文件。(我指的是公用文件夹下面的文件夹)

  • 确保公用文件夹中的.htaccess文件如下所示

        <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> 
    
    
    选项-多视图
    重新启动发动机
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(+)/$http://%{http_HOST}/$1[R=301,L]
    重写cond%{REQUEST_FILENAME}-F
    重写规则^index.php[L]
    
  • 你的“uploadImg”目录不在“public”目录中,正如其他人所说,这是根据你的截图。 “public”中是否有另一个uploadImg目录? 有三个非常重要的问题尚未解决

  • 您的数据库在表中显示的路径是什么

  • {{HTML::image('uploadImg/B05BgJ_school-uniform.jpg')}
    的输出是什么
  • 一旦upl,实际图像文件位于何处