Laravel4无法创建目录,尽管我给予了正确的权限 [英] Laravel4 unable to create a directory although I gave correct permissions

查看:257
本文介绍了Laravel4无法创建目录,尽管我给予了正确的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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..

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

,我什至重新启动了Apache服务器. 我已经搜寻了24小时左右,但仍然无法弄清楚. 这是路线和视图文件.

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.

// 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>

目前,在您的帮助下,我对routes.php所做的事情

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

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

我授予的权限是 sudo chmod -R 777存储

推荐答案

这是您可以使它起作用的方法:

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

告诉Laravel这样将文件写入该文件夹:

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

$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());

});

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

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

这篇关于Laravel4无法创建目录,尽管我给予了正确的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆