【发布时间】:2015-04-09 20:26:03
【问题描述】:
我可以更改我的代码以将上传的图片保存在公共目录中,但当我想将他们上传的图片作为他们公司的名称保存在文件夹中时则不行。例如有效的方法:
/public/company_img/<filename>.jpg
如果用户的公司名称是 Foo,当他们保存上传的图片时我想要这个:
/public/company_img/foo/<filename>.jpg
这是在我的控制器中:
$image = Input::file('company_logo');
$filename = $image->getClientOriginalName();
$path = public_path('company_img/' . Auth::user()->company_name . '/' . $filename);
// I am saying to create the dir if it's not there.
File::exists($path) or File::makeDirectory($path); // this seems to be the issue
// saving the file
Image::make($image->getRealPath())->resize('280', '200')->save($path);
只需查看它,您就可以轻松了解它在做什么。我的日志没有显示任何内容,并且在我点击更新按钮后浏览器变为空白。任何想法
【问题讨论】:
-
执行 PHP 的用户(即网络服务器)是否具有在该位置创建文件和文件夹所需的权限?
-
@Joe 是的。我只得到一个空白浏览器。没有日志,没有错误。
-
File::exists($path) or File::makeDirectory($path);是有效的 PHP 语法吗?我从未见过以这种格式编写的 IF 语句。 -
你能发布你完整的控制器功能吗?空白页可能只是因为您的控制器没有回显或返回任何内容
-
@shock_gone_wild 见这里:
http://laravel.io/bin/xKY8P
标签: laravel laravel-5 intervention