我正在添加编辑已在我正在构建的购物车应用上传的图像的功能 . 我可以上传图片了 . 除了图像文件上传之外,我还能够完美地编辑每个字段 .
我尝试使用我在上传功能中使用的相同代码基本上上传现有的图像,但它不起作用并引发错误
Call to a member function getClientOriginalExtension() on a non-object
我正在使用Laravel框架进行干预,并进入干预的主要站点,它没有显示更新或编辑方法 . 它只显示了一个删除方法 .
我需要一些帮助来弄清楚如何在postEdit函数中更新图像 .
我真的已经尝试了我所知道的一切,并且已经用谷歌研究了这个并且无法解决这个问题 .
我的问题在于这行代码:
File::update('public/'.$product->image);
谢谢你正确的方向 .
这是图片上传功能(工作完美)
public function postCreate() {
$validator = Validator::make(Input::all(), Product::$rules);
if ($validator->passes()) {
$product = new Product;
$product->category_id = Input::get('category_id');
$product->title = Input::get('title');
$product->description = Input::get('description');
$product->price = Input::get('price');
$image = Input::file('image');
$filename = time() . '.' . $image->getClientOriginalExtension();
$path = public_path('img/products/' . $filename);
Image::make($image->getRealPath())->resize(468, 249)->save($path);
$product->image = 'img/products/'.$filename;
$product->save();
return Redirect::to('admin/products/index')
->with('message', 'Product Created');
}
return Redirect::to('admin/products/index')
->with('message', 'Something went wrong')
->withErrors($validator)
->withInput();
}
这是编辑图像上传功能,我无法工作 .
public function postEdit() {
$product = Product::find(Input::get('id'));
if ($product) {
File::update('public/'.$product->image);
$product->update(Input::all());
return Redirect::to('admin/products/index')
->with('message', 'Product Updated');
}
return Redirect::to('admin/products/index')
->with('message', 'Something went wrong, please try again');
}
1 回答
首先,没有方法为
File
外观称为更新 .您必须重新处理图像才能更新它 .
其次,错误是从上传中抛出的 . 这可能是因为图像没有正确地通过表单发送 .
确保您的表单上的文件属性已打开 .
如果您的文件仍未发送,请检查您的php.ini设置,因为图像的文件大小可能会大于
post_max_size
或upload_max_filesize
中设置的值,大于该大小的值 .也改变线;
至
要通过干预编辑图像,您需要保存文件 .
使用;
然后你可以做;