无法将图像数据写入 Laravel 中的路径

Ale*_*nik 3 laravel-4

我和这个人有同样的错误:

另一个线程

基本上我的错误是将图像上传到特定路径,我的代码如下:

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 = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
        Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products'.$filename);
        $product->image = 'public/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();

} 
Run Code Online (Sandbox Code Playgroud)

我只是想学习 laravel 电子商务网络应用程序的教程。

我想问题是我的目录中没有写权限,如何在我的目录中添加写权限。IE 公共文件夹,我用谷歌搜索了几个地方,但我不明白我必须编辑什么?

IE htaccesss 文件或者我可以在 cmd 上进行写入更改吗?还有我如何检查目录被写保护的天气。

附注。我正在使用窗户。我附上了错误的截图。

错误

谢谢你。

VF_*_*VF_ 5

您可能想要更改日期格式,因为 Windows 不允许在文件名中使用冒号:

$filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();

而且您可能还想在路径中添加一个斜杠,这样它就不会将文件名连接到文件夹路径:

Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products'.$filename);