上传文件不保存在本地文件夹中,而是保存在数据库显示数据Laravel

时间:2016-12-12 08:53:02

标签: javascript php laravel image-uploading jquery-file-upload

上周我和laravel一起学习,现在我坚持使用上传文件。 我有搜索并尝试另一种方式,但仍然没有工作。

我已按此编码

public function store(Request $request)
{		
  $article = new Article();  
  $article->title = Input::get('title');
  $article->description = Input::get('description');
  $article->author = Input::get('author'); 
  
  if($request->hasFile('image') ==  "")
  {
    $article->image = $request->image;
  } else
  {
    $file = Input::file('image');
    //upload path
    $destinationPath = 'img/gallery/';
    //getting timestamp
    $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
    //setting name
    $filename = $file->getClientOriginalName(). '-' .$timestamp;  
    $article->image = $filename; 
    //move to path              
    $file->move($destinationPath,  $filename);                
  }

  $article->save(); 

  // sending back with message 
  return redirect()->route('articles.index')->with('message', 'File Success added!');               
}

适用于型号代码

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
	protected $fillable =
	[		
		'title', 
		'author', 
		'description', 
		'image'
	];
}

这对于观看代码

<div class="form-group">
	{!! Form::label('image', 'Choose an image') !!}
	{!! Form::file('image', null, ['class' => 'form-control', 'required' => '']) !!}
	<span id="image-error" class="help-block"></span>
</div>
<div class="form-group">     
	{!! Form::label("image","Preview Image") !!}
	<div class="image articles auth">
		@if(isset($articles))
			<img class="fit-cover" src="{{asset('img/gallery/'.$article->image.'')}}" id="showPicture" /> 
		@else
			<img class="fit-cover" src="http://placehold.it/625x1200" id="showPicture" /> 
		@endif         
	</div>
</div>

其他人输入的代码成功。但不适用于文件图像。 在数据库图像列中成功显示。但在本地文件映像中不存储在文件夹中。因此图像无法显示。

  

http://localhost:8000/img/gallery/fashion-man-person-hand.jpg

谢谢大师:)

我上传图片是否有错误 enter image description here

0 个答案:

没有答案