"C:xampptmpphp6A75.tmp"文件不存在或不可读



我想上传larvel-6.2中的图像,但显示"C:\examplep\tmp\php99C0.tmp"文件不存在或不可读。我的管理员:

class AdminController extends Controller
{
protected function uploadImages($file){
$year = Carbon::now()->year;
$imagePath = "/upload/images/{$year}/";
$filename= $file->getClientOriginalName();
$file = $file->move(public_path($imagePath) , $filename);
$sizes=['300' , '600' , '900'];
// resize the image to a width of 300 and constrain aspect ratio (auto height)
$url['images'] = $this->resize($file->getRealPath() , $sizes , $imagePath , $filename);
$url['thumb'] = $url['images'][$sizes[0]];
return $url;
}

private function resize($path , $sizes , $imagePath , $filename){
$images['original'] = $imagePath . $filename ;
foreach ($sizes as $size){
$images[$size] = $imagePath ."{$size}_" . $filename ;
Image::make($path)->resize($size, null, function ($constraint) {
$constraint->aspectRatio();
})->save(public_path($images[$size]));
}
return $images;
}
}

和我的CourseController存储功能代码:

public function store(CourseRequest $request)
{

$imageUrl = $this->uploadImages($request->file('images'));
auth()->user()->course()->create(array_merge($request->all() , ['images' => $imageUrl]));

return redirect(route('courses.index'));
}

我的表单视图代码:我的表单查看代码:我的表单视图代码:我的表单查看代码:我的表单视图代码:我的表单查看代码:


<form action="{{route('courses.store')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
@include('Admin.section.errors')
<div class="form-group">
<label for="title" class="bmd-label-floating text-white">Course Title</label>
<input type="text" class="form-control" name="title" id="title" placeholder="Enter Course title" value="{{old('title')}}">
</div>
<div class="form-group col-md-4">
<label for="Type">Course Type</label>
<select id="Type" name="type" class="form-control">
<option value="vip" class="text-dark">VIP</option>
<option value="cash" class="text-dark">Cash</option>
<option value="free" class="text-dark" selected>free</option>
</select>
</div>
<div class="form-group mt-3">
<label for="body" class="bmd-label-floating text-white">Course Body</label>
<textarea rows="15" class="form-control" name="body" id="body" placeholder="Enter Course body">{{old('body')}}</textarea>
</div>
<div class="form-file-upload mt-4">
<label for="pictures" class=" text-white">Course Pictures</label>
<input type="file" name="images" class="form-file-upload" id="pictures"  placeholder="Enter pictures" value="{{old('images')}}">
</div>
<div class="form-group mt-5">
<label for="tags" class=" text-white">Course Price</label>
<input type="text" name="price" class="form-control" id="tags"  placeholder="Enter Price" value="{{old('price')}}">
</div>
<div class="form-group mt-1">
<label for="tags" class=" text-white">Course Tags</label>
<input type="text" name="tags" class="form-control" id="tags"  placeholder="Enter Tags" value="{{old('tags')}}">
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>

请帮帮我。

如果使用Storage类,则可以将图像移动到存储文件夹中的正确路径中。

Storage::disk('local')->put('/uploads/images/' . $year .'/', $filename);

您需要运行命令PHP Artisan storage:link来在存储文件夹和公共文件夹之间创建符号链接。

相关内容

  • 没有找到相关文章

最新更新