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::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);
});
There's multiple arguments you can use.
You can create a directory using defaults.
This will return true if directory was able to be created in the /path/to directory. The file mode of the created directory is 0777.
You can specify the mode.
This will return true if directory was able to be created in the /path/to directory. The file mode of the created directory will be 0775.
You can also create the directories recursively.
No, actually it's
Also, you may try this:
Update: Actually it does work,
mkdir
is being used behind the scene. This is the source:For deleting:
Check the source at following path (in your local installation):
Thanks to The Alpha. Your answer helped me, here is a laravel 5 way to do it for those who use the later version :
This will create a directory in
storage/app/path/to
Retrieve the directory you just created with :