public function closeEditor(Request $request) { $dbxClient = $this->getDropboxClient(); $LocalAddress = $request->input('LocalAddress'); $LocalName = $request->input('LocalName'); $DropBoxFile = $request->input('DropBoxFile'); // $dropboxFileName = $request->input('fileName'); file_put_contents($LocalAddress, $_POST['text']); $editContent = array(); $editContent[0] = htmlspecialchars($_POST['text']); //updated text $editContent[1] = $LocalAddress; // full local folder name with location $editContent[2] = $LocalName; //full local file name $editContent[3] = $DropBoxFile; //full dropbox path with name $LocalName = str_replace(' ', '', $LocalName); $f = fopen($editContent[1], "rb"); $result = $dbxClient->uploadFile($editContent[3], dbx\WriteMode::force(), $f); fclose($f); $dropboxObject = Dropbox::where('userId', Auth::id())->firstOrFail(); $access_token = $dropboxObject->accessToken; $dropboxClient = new dbx\Client($access_token, "PHP-Example/1.0"); $folderMetadata = $dropboxClient->getMetadataWithChildren("/"); $this->deleteFile($LocalAddress); return view('pages.dropbox')->with('dropboxData', $folderMetadata); }
} else { $userConfig[0] = 0; } if ($googleDriveId == 1) { $userConfig[1] = 1; } else { $userConfig[1] = 0; } return view('pages.settings')->with('userConfig', $userConfig); }); Route::get('/home', function () { if (Auth::guest()) { return view('auth.login'); } $userConfig = array(); $dropboxId = Dropbox::where('userId', Auth::id())->count(); //var_dump($dropboxId); $googleDriveId = GoogleDrive::where('userId', Auth::id())->count(); if ($dropboxId == 1) { $userConfig[0] = 1; } else { $userConfig[0] = 0; } if ($googleDriveId == 1) { $userConfig[1] = 1; } else { $userConfig[1] = 0; } return view('pages.home')->with('userConfig', $userConfig); }); Route::post('/save', 'EditController@closeEditor');
public function getDropboxClient() { $dropboxObject = Dropbox::where('userId', Auth::id())->firstOrFail(); $access_token = $dropboxObject->accessToken; $dbxClient = new dbx\Client($access_token, "PHP-Example/1.0"); return $dbxClient; }