Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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 编辑不';我无法上传文件_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 编辑不';我无法上传文件

Php 编辑不';我无法上传文件,php,laravel,laravel-5,Php,Laravel,Laravel 5,我是拉雷维尔的新手,在开始处理真实文件而不是伪造文件时遇到了麻烦。 我想做的是: 我有存储功能-将图像从pc放入我的网站。 但当我试图进行编辑时,所有的程序都崩溃了——它对图像不起作用:因为我使用的是提交功能 我的光电控制器: public function create() { $categories = Category::all(); return view('photo.create', compact('photo','categories')); } /** * Store

我是拉雷维尔的新手,在开始处理真实文件而不是伪造文件时遇到了麻烦。 我想做的是: 我有存储功能-将图像从pc放入我的网站。 但当我试图进行编辑时,所有的程序都崩溃了——它对图像不起作用:因为我使用的是提交功能 我的光电控制器:

public function create()
{
  $categories = Category::all();
  return view('photo.create', compact('photo','categories'));
}
/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $this->validate($request, [
   'title' => 'required|min:3',
   'image_url'=> 'required',
   'category_id' => 'required',
    ]);

     $photo = new Photo;
     if ($request->hasFile('image_url')) {
                     $file = $request->file('image_url');

                    $fileName = $request->image_url->store('');
                    $photo->image_url =  $fileName;
                 }

     $photo->title = $request->input('title');

     $photo->description = $request->input('description');
     $photo->category_id = $request->input('category_id');
     $photo->save();

     $request->session()->flash('create', $request->title. "Sekmingai sukurta");
     $path = $request->image_url->store('public');
     return redirect()->route('photos.index');

}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    return view('photos.index', compact('photo'));
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
  $photo = Photo::find($id );
  $categories = Category::all();

    return view('photo.edit', compact('photo', 'categories'));
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function submit(Request $request, $id)
{

  $photo = Photo::find($id);

  $photo->title = $request->input('title');
  $photo = new Photo;
  if ($request->hasFile('image_url')) {
                  $file = $request->file('image_url');

                 $fileName = $request->image_url->store('');
                 $photo->image_url =  $fileName;
              }

  $photo->description = $request->input('description');
  $photo->category_id = $request->input('category_id');

  $photo->update();

  $request->session()->flash('update', $request->title. "Sekmingai papildyta");
  $path = $request->image_url->store('public');
  return redirect()->route('photo.edit', $photo->id);

} 
当我试图编辑文件并上载新照片时-我遇到错误:

“对字符串的成员函数store()的调用”

这表明错误在这一行:

$path = $request->image_url->store('public');

有人能建议吗?谢谢你

这样试试:
$path=$request->file('image_url')->store('public')!!我已经尝试过了:然后我得到了错误:“在null上调用成员函数store()”是,如果您没有发送文件,那么您应该将其添加到if语句
if($request->hasFile('image\u url'))
,以确保有文件;)谢谢你的帮助,但我有if:if($request->hasFile('image\u url')){$file=$request->file('image\u url');$fileName=$request->image\u url->store(“”);$photo->image\u url=$fileName;}像这样试试:
$path=$request->file('image\u url')->store('public')!!我已经尝试过了:然后我得到了错误:“在null上调用成员函数store()”是,如果您没有发送文件,那么您应该将其添加到if语句
if($request->hasFile('image\u url'))
,以确保有文件;)谢谢你的帮助,但我有if:if($request->hasFile('image_url')){$file=$request->file('image_url');$fileName=$request->image_url->store(“”);$photo->image_url=$fileName;}