Php 拉威尔无法保存照片
我有下面的功能代码,但它不会将照片保存在数据库或文件路径中 密码 dd$request->all;上面的代码 有什么想法吗 使现代化 根据下面的Nabil Farhan回答,我忘记了enctype=multipart/form数据,但现在我得到了Php 拉威尔无法保存照片,php,laravel,Php,Laravel,我有下面的功能代码,但它不会将照片保存在数据库或文件路径中 密码 dd$request->all;上面的代码 有什么想法吗 使现代化 根据下面的Nabil Farhan回答,我忘记了enctype=multipart/form数据,但现在我得到了 Intervention \ Image \ Exception \ NotReadableException Unable to find file (). 仍然无法保存我的照片 更新2 我再次添加请求,现在在添加enctype=multipart
Intervention \ Image \ Exception \ NotReadableException
Unable to find file ().
仍然无法保存我的照片
更新2
我再次添加请求,现在在添加enctype=multipart/form数据后,它变得很奇怪:
array:5 [▼
"_token" => "awAvc7F8lOv9vKkfwyiTFj7jnQGszv8xjLQxcwRH"
"name" => "kerupuk"
"price" => "2000"
"type_id" => "3"
"photo" => UploadedFile {#805 ▼
-test: false
-originalName: "kerupuk.jpg"
-mimeType: "image/jpeg"
-error: 0
#hashName: null
path: "C:\Windows\Temp"
filename: "phpB195.tmp"
basename: "phpB195.tmp"
pathname: "C:\Windows\Temp\phpB195.tmp"
extension: "tmp"
realPath: false
aTime: 2019-02-12 04:57:39
mTime: 2019-02-12 04:57:39
cTime: 2019-02-12 04:57:39
inode: 0
size: 43933
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\Windows\Temp\phpB195.tmp"
}
]
为什么我的摄影场会变成这样
总之,这是我在blade中的表格:
{{ Form::open(array('route' => 'menus.store', 'files' => true)) }}
<div class="row">
<div class="col-md-12">
<h5>Name</h5>
{{ Form::text('name', null, array('class' => 'form-control')) }}
</div>
<div class="col-md-12">
<h5>Price</h5>
{{ Form::number('price', null, array('class' => 'form-control')) }}
</div>
<div class="col-md-12">
<h5>Photo</h5>
{{ Form::file('photo', array('class' => 'form-control', 'id' => 'photo')) }}
</div>
<div class="col-md-12">
<h5>Type</h5>
<select name="type_id" id="type_id" class="form-control">
<option value="">-- Select --</option>
@foreach($types as $type)
<option value="{{$type->id}}">{{$type->name}}</option>
@endforeach
</select>
</div>
<div class="col-md-12 mt-2">
{{ Form::submit('Save', array('class' => 'btn btn-primary')) }}
</div>
</div>
{{ Form::close() }}
photo=>air putih.jpg不应该是字符串。它应该有一些关于文件的更多信息
我想问题出在你的刀片文件里。请检查您是否在表单标记中使用了enctype='multipart/form data'
编辑
改变这个
Image::make($photo)->resize(500, 500)->save($location);
对此
Image::make($photo->getRealPath())->resize(500, 500)->save($location);
试着改变这一行
Image::make($photo)->resize(500, 500)->save($location);
Image::make($photo->getRealPath())->resize('200','200')->save($location);
您的realpath为false检查配置您应该尝试以下操作:
您的视图文件如下所示:
太棒了,我完全忘记了:。现在我找不到文件。请现在再试。您能在这里更新您的表单代码吗。@Md.SukelAliupdated@mafortis您的realpath为false配置中存在一些错误引用这两个链接,正如我在nabil回答中所评论的,返回图像源不可读您的laravel版本??您可以转储$locationC:\laragon\www\hrdapp\public\images/MenuItem-1549948461.jpg您的驱动器类型是“imagick”还是“gd”,请同时检查对公用文件夹的权限
Image::make($photo->getRealPath())->resize(500, 500)->save($location);
Image::make($photo)->resize(500, 500)->save($location);
Image::make($photo->getRealPath())->resize('200','200')->save($location);
{!! Form::open(['route' => 'menus.store', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post','files'=>true]) !!}
<div class="row">
<div class="col-md-12">
<h5>Name</h5>
{{ Form::text('name', null, array('class' => 'form-control')) }}
</div>
<div class="col-md-12">
<h5>Price</h5>
{{ Form::number('price', null, array('class' => 'form-control')) }}
</div>
<div class="col-md-12">
<h5>Photo</h5>
{{ Form::file('photo', array('class' => 'form-control', 'id' => 'photo')) }}
</div>
<div class="col-md-12">
<h5>Type</h5>
<select name="type_id" id="type_id" class="form-control">
<option value="">-- Select --</option>
@foreach($types as $type)
<option value="{{$type->id}}">{{$type->name}}</option>
@endforeach
</select>
</div>
<div class="col-md-12 mt-2">
{{ Form::submit('Save', array('class' => 'btn btn-primary')) }}
</div>
</div>
{{ Form::close() }}
use Input;
public function store(Request $request)
{
$this->validate($request, array(
'name' => 'required',
'price' => 'required|numeric',
'type_id' => 'required|numeric',
'photo' => 'required',
));
$item = new Menu;
$item->name = $request->input('name');
$item->price = $request->input('price');
$item->type_id = $request->input('type_id');
if ($request->hasFile('photo')) {
$photo = Input::file('photo');
$filename = 'MenuItem' . '-' . time() . '.' . $photo->getClientOriginalExtension();
$location = public_path('images/'. $filename);
$img = Image::make($photo->getRealPath());
$img->resize(500, 500, function ($constraint) {
$constraint->aspectRatio();
})->save($location);
$item->photo = $filename;
}
$item->save();
Session::flash('success', 'Menu Item Saved Successfully.');
return redirect()->back();
}