Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用PHP和Laravel存储上载的图像_Php_Laravel_Laravel 5 - Fatal编程技术网

无法使用PHP和Laravel存储上载的图像

无法使用PHP和Laravel存储上载的图像,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在学习Laravel,并试图创建一个网页来上传相册。我已经阅读了关于验证的laravel文档,每个字段都在验证中。但是,单击submit后,图像不会发布到store方法 路由是在web.php中设置的 Route::get('/albums/create', 'AlbumsController@create')->name("album-create"); Route::post('/albums/store', 'AlbumsController@store')->name("

我正在学习Laravel,并试图创建一个网页来上传相册。我已经阅读了关于验证的laravel文档,每个字段都在验证中。但是,单击submit后,图像不会发布到store方法

路由是在web.php中设置的

Route::get('/albums/create', 'AlbumsController@create')->name("album-create");
Route::post('/albums/store', 'AlbumsController@store')->name("album-store");
表格代码如下所示:

<div class="container">

  <h2> Create New Album </h2>

    <form method="post" action="{{ route('album-store') }}" enctype="multipart/form-data">
      <input type="hidden" name="_token" value="{{ csrf_token(@csrf) }}">

        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" name="name" id="name" placeholder="Enter Name: ">
        </div>
        <div class="form-group">
            <label for="name">Description</label>
            <input type="text" class="form-control" name="description" id="description"  placeholder="Enter description">
        </div>
        <div class="form-group">
            <label for="name">Cover Image</label>
            <input type="file" class="form-control" name="cover_image" id="cover-image" placeholder="cover-image">
        </div>
        <button type="submit" class="btn btn-primary">Submit</button>
      </form>

当我在填写字段后单击表单上的提交时,仍然会收到错误“封面图像”是必需的

html中的字段是
cover\u image
验证为
封面图像时


封面图片

属性的标签
被设置为指向id=“name”的字段,与问题无关,但我认为您需要查看html文件,它需要注意。

html中的字段是
封面图片
验证为
封面图像时


封面图片

属性的标签
设置为指向id=“name”的字段,与问题无关,但我认为您需要查看html文件,它需要一些注意。

您的封面图像输入字段名称为封面图像,您将该值作为封面图像写入表单组输入字段进行验证,如下图所示


封面图片

您的封面图像输入字段名为cover_image,您获取该值并将其验证为封面图像写入表单组输入字段,如下图所示


封面图片

输入的名称是
cover\u image
,而不是
cover image
。传入的是输入名称,而不是id。输入的名称是
cover\u image
,而不是
cover image
。传入的是输入名称,而不是id。这是否意味着验证实际上是使用字段“name”完成的?我以为是“id”,那么这是否意味着验证实际上是使用字段“name”完成的呢?我以为是“身份证”
public function store(Request $request) {
  $this->validate($request, [
    'name' => 'required',
    'description' => 'required',
    'cover-image' => 'required'
  ]);

  $filenameWithExtension = $request->file('cover-image')->getClientOriginalName();

      $filename = pathinfo($filenameWithExtension, PATHINFO_FILENAME);

      $extension = $request->file('cover-image')->getClientOriginalExtension();
// time stamping the images uplaoded
      $filenameToStore = $filename . '_' . time() . '.' . $extension;

// saving the file to the disk (can be found in 'storage/app/public/album_covers..')
      $request->file('cover-image')->storeAs('public/album_covers', $filenameToStore);

  $album = new Album();
  $album->name = $request->input('name');
  $album->description = $request->input('description');
  $album->cover_image = $filenameToStore;
  $album->save();