I want to save file in folder outside Laravel project to folder on local machine for example 'C:/uploads'. When the project installed on local machine is saved in 'C:/uploads' folder but when the project is installed online on server don't save in 'C:/uploads'.
In filesystems.php I put like as:
'local' => [
'driver' => 'local',
//'root' => storage_path('app/public'),
//'root' => public_path('uploads'),
'root'=>'C:\uploads',
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
In HomeController.php function:
$files = Input::file('images');
$file_count = count($files);
$uploadcount = 0;
foreach($files as $file) {
//$destinationPath = 'uploads';
$filename = time() .'-'.$file->getClientOriginalName();
//$file->move($destinationPath, $filename);
Storage::disk('local')->put($filename, File::get($file));
$image=new Image();
$image->sparepart_id = $id;
$image->Filename=$filename;
$image->save();
$uploadcount ++;
}
You can use Laravel's environment variables to achieve this.
In your .env file (example 1)
Or define the application environment (example 2)
Then change these values accordingly for your local env and server env and use them in your code to check what env is being used.
In your home controller you can simply use the Storage facade without the disk call to use the default disk defined in ex 1. Or you could check for APP_ENV and save or not save to the desired disk based on that.