0
Once again, I really need your help. You are giving me the following error when uploading the image to Laravel 5.4:
Method getClientOrinalExtension does not exist.
Next is my controller and view:
Controller
namespace App\Http\Controllers;
use App\Posts;
//use Illuminate\Http\File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Post;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\File;
class PostController extends Controller
{
public function index()
{
//
}
public function create()
{
if(Input::file('imagem'))
{
$imagem = Input::file('imagem');
$extensao = $imagem->getClientOrinalExtension();
if($extensao != 'jpg' && $extensao != 'png')
{
return back()->with('Erro','Erro: Este arquivo não é uma imagem JPG ou PNG');
}
}
$post = new Posts();
$post->titulo = Input::get('titulo');
$post->conteudo = Input::get('conteudo');
$post->imagem ="";
$post->save();
if(Input::file('imagem'))
{
File::move($imagem,public_path().'/imagem-post/post-id_'.$post->id.'.'.$extensao);
$post->imagem = public_path().'/imagem-post/post-id_'.$post->id.'.'.$extensao;
$post->save();
}
return redirect('/');
}
}
View:
@extends('main')
@section('content')
<form action="{{ url('criar-post') }}" method="post" enctype="multipart/form-data">
{!! csrf_field() !!}
@if(session('erro'))
<div class="alert alert-danger">
{{session('erro')}}
</div>
@endif
<div class="form-group">
<label for="titulo">Título</label>
<input name="titulo" type="text" class="form-control" id="titulo" placeholder="Título">
</div>
<div class="form-group">
<label for="conteudo">Conteúdo</label>
<textarea class="form-control" name="conteudo" rows="8" cols="40"></textarea>
</div>
<div class="form-group">
<label for="imagem">Imagem</label>
<input type="file" id="imagem" name="imagem">
</div>
<button type="submit" class="btn btn-primary">Salvar</button>
</form>
@endsection
that error is gone, is recording the other data in the database, but is not recording the image path. From what I noticed, it is not even uploading the image, because the destination folder is empty, and is giving the following error: Rename(jpg,C: xampp htdocs Sistema53 public/image-post/post-id_.jpg): The system could not locate the specified file. (code: 2)
– Daniel dos Santos
You have to give permission in folder temp I think you are
c:\windows\temp
@Danieldossantos– novic
Sorry @Virgilionovic, what is this "give permission"? How would you do that?
– Daniel dos Santos