我有问题让用户通过ajax请求>路由> controller @ method在laravel 4中创建文件夹。 我确实对url调用权方法测试了ajax成功请求。 当我使用mkdir或File::mkdir($path);(此方法存在吗?)时,我将得到响应Failed to load resource: the server responded with a status of 500 (Internal Server Error)并且无法创建新文件夹..该如何解决?
mkdir
File::mkdir($path);
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
route.php
Route::post('admin/article/addimagegallery', 'AdminDashboardController@addImagegallery');
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);
另外,您可以尝试以下操作:
$path = public_path().'/images/article/imagegallery/' . $galleryId; File::makeDirectory($path, $mode = 0777, true, true);
更新: 确实有效,mkdir正在幕后使用。这是来源:
/** * 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);
在以下路径中检查源(在本地安装中):
根目录/供应商/laravel/framework/src/Illuminate/Filesystem/Filesystem.php