Created
February 11, 2014 19:55
-
-
Save patrickcurl/8942836 to your computer and use it in GitHub Desktop.
Laravel upload files outside of laravel app directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ 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