Laravel 错误的公共路径文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17010056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel wrong public path file upload
提问by Stephan-v
I've deployed laravel with this guide.
我已经使用本指南部署了 laravel。
http://juniorgrossi.com/deploying-laravel-applications-on-a-shared-host/
http://juniorgrossi.com/deploying-laravel-applications-on-a-shared-host/
On my webserver I have a public_html file now containing all my publicly accesable files and a laravel folder containing the rest, so I've split up the default laravel structure for deployment.
在我的网络服务器上,我有一个 public_html 文件,现在包含我所有可公开访问的文件和一个包含其余文件的 laravel 文件夹,所以我已经拆分了默认的 laravel 结构以进行部署。
On my development server by default the public folder is resting inside the laravel folder instead of being on the same directory level.
默认情况下,在我的开发服务器上,公共文件夹位于 laravel 文件夹内,而不是位于同一目录级别。
The problem I'm getting though is when I use something like this:
我遇到的问题是当我使用这样的东西时:
// Upload the file
Input::upload('image', 'public/uploads', $filename);
Same with this.
与此相同。
// Upload the file
Input::upload('image', path('public') . 'uploads', $filename);
Instead of trying to use the uploads folder that is inside my public_html folder it tries looking for a public file inside my laravel folder now.
现在不是尝试使用我的 public_html 文件夹中的上传文件夹,而是尝试在我的 Laravel 文件夹中查找公共文件。
And I get a
我得到一个
Unable to create the "/uploads" directory
无法创建“/uploads”目录
Ofcourse on my development server the public folder is still inside the folder so it's logical.
当然,在我的开发服务器上,公用文件夹仍在文件夹内,所以这是合乎逻辑的。
How do I fix this?
我该如何解决?
采纳答案by Stephan-v
Fixed the paths.php to ../public_html
修复了paths.php 到../public_html
I've done this before but it failed since I accidentaly uploaded a png and my jcrop function wich crops and saves images failed because it currently onlt takes jpg. So that left me thinking my paths.php settings were no good while they actually were.
我以前做过这个,但它失败了,因为我不小心上传了一个 png,我的 jcrop 功能裁剪和保存图像失败,因为它目前只需要 jpg。所以这让我觉得我的 path.php 设置实际上并不好。
Thanks for helping out though everybody! (I feel like a fool.)
谢谢大家帮忙!(我觉得自己像个傻瓜。)
回答by The Alpha
You may try this (add a slash after the folder name)
你可以试试这个(在文件夹名称后加一个斜线)
Input::upload('image', path('public') . 'uploads/', $filename);
回答by Kylie
Maybe try this....just as a test
也许试试这个....作为测试
Input::upload('image', URL::to_asset('uploads/'), $filename);
回答by Melvin
You can also try Intervention/imagepackage. I'm using this and I find it very easy to use. It also has a resize and crop feature.
您也可以尝试 干预/图像包。我正在使用它,我发现它很容易使用。它还具有调整大小和裁剪功能。
It's easy as:
这很简单,因为:
Image::make(Input::file('file')->getRealPath())->save('uploads/' . $filename);
回答by Dennis Braga
In my case, I got the same problem. Then I created it manually, CHMODed the lil' bastard and it worked fine!
就我而言,我遇到了同样的问题。然后我手动创建了它,对这个小混蛋进行了 CHMOD 修改,效果很好!
Making a long history short (not so long...): just permission!
缩短悠久的历史(不是很长......):只是许可!
If you have the permission to Write/Read to the folder, you'll be cool! If you don't, you change the permissions! If you are unable to change it, put the uploaded files where the permissions allows you to access the file.
如果您有权限写入/读取到文件夹,你会很酷!如果不这样做,请更改权限!如果您无法更改它,请将上传的文件放在允许您访问文件的位置。