laravel 尽管我赋予了正确的权限,但 Laravel4 无法创建目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20914268/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:50:17  来源:igfitidea点击:

Laravel4 unable to create a directory although I gave correct permissions

laravellaravel-4

提问by seoyoochan

Laravel4 unable to create a directory although I gave correct permissions. FileException error happened, http://s28.postimg.org/xkor8srxp/2014_01_03_2_53_18.png. I tried lots of permissions..

尽管我给了正确的权限,但 Laravel4 无法创建目录。发生 FileException 错误,http://s28.postimg.org/xkor8srxp/2014_01_03_2_53_18.png 。我尝试了很多权限..

  • sudo chmod -R 777 storage
  • sudo chmod -R 707 storage
  • sudo chmod -R o+rwx storage
  • 须藤 chmod -R 777 存储
  • 须藤 chmod -R 707 存储
  • 须藤 chmod -R o+rwx 存储

and I even restarted Apache server. I have been googling 24 hours or so, and still can't figure out.. Here are the routes and view files.

我什至重新启动了Apache服务器。我已经在谷歌上搜索了 24 小时左右,仍然无法弄清楚.. 以下是路线和视图文件。

// routes.php

Route::post('handle-form', function()
{
    $name = Input::file('book')->getClientOriginalName();
Input::file('book')->move('/storage/directory', $name);
return 'File was moved.';
});

// form2.blade.php
<form action="{{ url('handle-form') }}"
  method="POST"
  enctype="multipart/form-data">

<input type="file" name="book" />
<input type="submit">
</form>

Currently what I did to the routes.php by following your help,

目前我按照你的帮助对 routes.php 做了什么,

Route::post('handle-form', function()
{
$name = Input::file('book')->getClientOriginalName();
Input::file('book')->move(public_path().'/storage/directory', $name); 
return 'File was moved.';
});

and the permission I gave was sudo chmod -R 777 storage

我给的许可是sudo chmod -R 777 storage

回答by Antonio Carlos Ribeiro

This is what you can do to make it work:

这是您可以执行的操作:

Create a directory in your public folder, or any other place:

在您的公共文件夹或任何其他位置创建一个目录:

 mkdir -p /var/www/your-site-path/public/storage/directory

Make it writable by your webserver

使其可由您的网络服务器写入

sudo chmod 770 /var/www/your-site-path/public/storage/directory

sudo chown username:www-data /var/www/your-site-path/public/storage/directory
or
sudo chown dongju:httpd /var/www/your-site-path/public/storage/directory

Tell Laravel to write the file to that folder this way:

告诉 Laravel 以这种方式将文件写入该文件夹:

$name = Input::file('book')->getClientOriginalName();

Input::file('book')->move(public_path().'/storage/directory', $name);    

Using this method I create here those two routes and it worked for me:

使用这种方法,我在这里创建了这两条路线,它对我有用:

Route::get('form', function() {
    return 

        Form::open(array('url' => 'http://your-dev-server-address/upload', 'files' => true)) .

        Form::file('book', $attributes = array()) .

        Form::submit('submit') .

        Form::close();
});

Route::post('upload', function() {

    Input::file('book')->move(public_path().'/storage/directory', Input::file('book')->getClientOriginalName());

});

The first one /formwill show you a file upload form and the second one /uploadwill get the file and save it to the correct path.

第一个/form将向您显示文件上传表单,第二个/upload将获取文件并将其保存到正确的路径。

回答by Black Mamba

In my case, the problem was that I was using an environment variable which was not available at the time of making call so All I had to do was to change the variable I was using.

就我而言,问题是我使用了一个在调用时不可用的环境变量,所以我所要做的就是更改我正在使用的变量。

In short please check the path you are specifying.

简而言之,请检查您指定的路径。