Skip to content

Instantly share code, notes, and snippets.

@patrickcurl
Created February 11, 2014 19:55
Show Gist options
  • Save patrickcurl/8942836 to your computer and use it in GitHub Desktop.
Save patrickcurl/8942836 to your computer and use it in GitHub Desktop.
Laravel upload files outside of laravel app directory.
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException
Unable to create the "/home/rahl/www/recycleabook.com/files/" directory
open: /home/rahl/www/recycleabook.com/rab/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/File/File.php
return $target;
}
protected function getTargetFile($directory, $name = null)
{
if (!is_dir($directory)) {
if (false === @mkdir($directory, 0777, true)) {
throw new FileException(sprintf('Unable to create the "%s" directory', $directory));
}
} elseif (!is_writable($directory)) {
Path : is /home/rahl/www/recycleabook.com/files
this is a SSHFS folder that actually links to another server which is the central file server.
It is chown -R www-data:www-data
&& chmod -R 777
Route::get('test', function(){
return View::make('test');
});
Route::post('test', function(){
Config::set('app.debug', true);
$file = Input::file('file'); // your file upload input field in the form should be named 'file'
$destinationPath = '/home/rahl/www/recycleabook.com/files/';
$filename = $file->getClientOriginalName();
//$extension =$file->getClientOriginalExtension(); //if you need extension of the file
$uploadSuccess = Input::file('file')->move($destinationPath, $filename);
if( $uploadSuccess ) {
return Response::json('success', 200); // or do a redirect with some message that file was uploaded
} else {
return Response::json('error', 400);
}
});
{{ Form::open(array('files' => true)) }}
{{Form::file('file', array('class' => 'file'))}}
{{Form::submit('Submit!')}}
{{Form::close()}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment