在laravel中创建文件夹 [英] create folder in laravel

查看:63
本文介绍了在laravel中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题让用户通过ajax请求>路由> controller @ method在laravel 4中创建文件夹.
我确实对url调用权方法测试了ajax成功请求.
当我使用mkdirFile::mkdir($path);(此方法存在吗?)时,我将获得响应Failed to load resource: the server responded with a status of 500 (Internal Server Error)并无法创建新文件夹..该如何解决?

I have problem let user create folder in laravel 4 through ajax request > route > controller@method.
I did test ajax success request to the url call right method.
When I use mkdir or File::mkdir($path); (is this method exist?) , I will get the response Failed to load resource: the server responded with a status of 500 (Internal Server Error) and fail to create new folder.. how to solve it ?

route.php

route.php

Route::post('admin/article/addimagegallery', 'AdminDashboardController@addImagegallery');

AdminDashboardController

AdminDashboardController

public function addImagegallery()
{
    if (Request::ajax())
    {
        …
        $galleryId = 1; // for test
        $path = public_path().'/images/article/imagegallery/'.$galleryId;
        File::mkdir($path);
    }
}

js

$.ajax({
    url: 'addimagegallery',
    type: 'POST',
    data: {addimagegallery: 'addimagegallery'},
})
.done(function(response) {
    console.log(response);
});

推荐答案

不,实际上是

File::makeDirectory($path);

此外,您可以尝试以下操作:

Also, you may try this:

$path = public_path().'/images/article/imagegallery/' . $galleryId;
File::makeDirectory($path, $mode = 0777, true, true);

更新:实际上,它确实可以工作,在后台使用了mkdir.这是来源:

Update: Actually it does work, mkdir is being used behind the scene. This is the source:

/**
 * Create a directory.
 *
 * @param  string  $path
 * @param  int     $mode
 * @param  bool    $recursive
 * @param  bool    $force
 * @return bool
 */
public function makeDirectory($path, $mode = 0777, $recursive = false, $force = false)
{
    if ($force)
    {
        return @mkdir($path, $mode, $recursive);
    }
    else
    {
        return mkdir($path, $mode, $recursive);
    }
}

要删除:

public function deleteDirectory($directory, $preserve = false);

在以下路径(在本地安装中)检查源:

Check the source at following path (in your local installation):

root/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php

root/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php

这篇关于在laravel中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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