Php 拉威尔行为疯狂-展示错误的图像

Php 拉威尔行为疯狂-展示错误的图像,php,laravel,Php,Laravel,我有一个网站satoshirps.site 当新用户注册时,他的个人资料照片保持为空。 然后转到上传个人资料图片 返回dashboard(www.satoshirps.site/dashboard)后,用户会看到上传的个人资料图片。现在转到删除当前配置文件图片,然后使用upload上载另一个配置文件图片 这一次返回到仪表板给出了旧的图片(这很奇怪) 当我尝试这件事时,我第二次成功上传了图片(我检查了我应用程序文件夹中的文件)。然后我没有得到正确的图像。lavarel是否有缓存,或者这是一个coo

我有一个网站satoshirps.site

当新用户注册时,他的个人资料照片保持为空。 然后转到上传个人资料图片

返回dashboard(www.satoshirps.site/dashboard)后,用户会看到上传的个人资料图片。现在转到删除当前配置文件图片,然后使用upload上载另一个配置文件图片

这一次返回到仪表板给出了旧的图片(这很奇怪)

当我尝试这件事时,我第二次成功上传了图片(我检查了我应用程序文件夹中的文件)。然后我没有得到正确的图像。lavarel是否有缓存,或者这是一个cookie问题。我再次尝试删除浏览器的缓存和cookie,但没有任何效果

上载页面:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Upload</title>
</head>
<body>
  @if(Session::has('success'))
      {{ Session::get('success') }}
@endif

@if(Session::has('error'))
        {{ Session::get('error') }}
@endif

  {{ Form::open(array('url' => 'upload', 'files' => true, 'method' => 'post')) }}
  {!! csrf_field() !!}
  {{ Form::file('image') }}
  {{ Form::submit('Upload') }}
  {{ Form::close() }}
</body>
</html>

上传
@if(会话::has('success'))
{{Session::get('success')}
@恩迪夫
@if(Session::has('error'))
{{Session::get('error')}
@恩迪夫
{{Form::open(数组('url'=>'upload','files'=>true,'method'=>'post'))}
{!!csrf_field()!!}
{{Form::file('image')}
{{Form::submit('Upload')}
{{Form::close()}}
控制器

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Input;
use Session;
use Redirect;
use Image;
use Storage;
use App\User;
use File;


class HomeController extends Controller
{
  /**
  * Create a new controller instance.
  *
  * @return void
  */
  public function __construct()
  {
    $this->middleware('auth');
  }

  /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
  public function index()
  {
    return view('home');
  }

  public function dashboard()
  {
    $user = Auth::user();
    return view('dashboard', compact('user'));
  }

  public function upload()
  {
    $user = Auth::user();
    return view('upload', compact('user'));
  }

  public function uploadsave(Request $request)
  {
    $user = Auth::user();
    if (Input::file('image')->isValid()) {
      $filename = 'profilepics/'.$user->username.'.jpg';
      File::delete($filename);
      $img = Image::make($_FILES['image']['tmp_name'])->encode('jpg',75)->resize(200,200)->save('profilepics/'.$user->username.'.jpg');
      $dbuser = User::where('id', $user->id)->first();
      $dbuser->photo_path = '/profilepics/'.$user->username.'.jpg';
      $dbuser->save();  //update user's profile picture location
      Session::flash('success', 'Upload successfull');
      return Redirect::to('upload');
    }
    else {
      // sending back with error message.
      Session::flash('error', 'Uploaded file is not valid');
      return Redirect::to('upload');
    }
  }


  public function deletephoto()
  {
    $user = Auth::user();
    $filename = 'profilepics/'.$user->username.'.jpg';
    File::delete($filename);
    if (file_exists($filename)) {
      echo "The image is not deleted";
    } else {
      echo "The image is deleted";
    }
  }
}
从,要删除文件,您应该使用
存储::删除($filename)

将图片保存在存储目录中,并通过在
用户控制器中创建如下路由为其提供服务:

public function profilePicture($user){
    $profile_picture_url = storage_path().'/profile_pictures/'.$user['id'].'/profile.jpg';

    if(!File::exists( $profile_picture_url ))
        App::abort(404);

    return Image::make($profile_picture_url)->response('jpg');
}
然后,在视图中,使用Laravel的
HTML
URL
帮助程序创建img标记:

HTML::image(URL::action('UsersController@profilePicture', array($user['id'])))

确保您已安装并可以继续

在新上载后按CTRL+F5键是否有效?您可以自己检查。我已经提供了网站的链接,但你的方法也不起作用。它说你的网站无法访问(编辑:你的URL不包括.site)。该网站可能会在某个时候关闭,因为我是一个自托管的网站,它运行在笔记本电脑上,有时会过热。但现在检查它的存储::删除($filename)将从App\storage\App\public\profilepics(不存在)中删除文件。但是图片存储在App\public\profilepics中阅读完整的文档,在配置部分清楚地提到了为什么不将图片保存在存储文件夹中?我也尝试过,但另一个问题是如何检索它们,因为“存储”将给出jpg存储的内容,而不是文件名。另外,我尝试在config/filesystem.php中更改存储路径,但都不起作用。
HTML::image(URL::action('UsersController@profilePicture', array($user['id'])))