Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ...
- Route::get('/update', function(){
- // define some vars
- $base = __DIR__.'/../';
- $temp_path = $base . 'storage/tmp';
- $controller_path = $base . 'app/Http/Controllers';
- $routes_path = $base . 'routes/';
- $routes_file = $routes_path . 'web.php';
- $home_controller = 'HomeController.php'; // update existing file
- $test_controller = 'TestController.php'; // will add new file
- // make tmp dir to download
- if ( ! file_exists($temp_path)) {
- mkdir($temp_path);
- }
- // keep backup ?!!
- $files_to_backup = [
- $controller_path . '/' . $home_controller,
- // some how list all files
- ];
- foreach ($files_to_backup as $file) {
- if( file_exists($file) )
- rename($file, $file.'.bk'); // move some where else??!!
- }
- // download update
- $fp = fopen ($temp_path . '/update.tmp', 'w+');
- $url = 'http://localhost/HomeController.php.txt';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 50);
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_exec($ch);
- curl_close($ch);
- fclose($fp);
- // override existing
- rename($temp_path.'/update.tmp', $controller_path . '/' . $home_controller);
- // add new file
- // assume that you have downloaded this file also
- // :P too lazy to make new file just for test
- $content = '<?php
- namespace App\Http\Controllers;
- class TestController extends Controller
- {
- public function index()
- {
- return view("welcome");
- }
- }';
- file_put_contents($controller_path . '/' . $test_controller, $content);
- // update routes
- $data = file_get_contents($routes_file);
- $data .= "
- Route::get('/test', 'TestController@index');
- "; // all the new routes :p
- file_put_contents($routes_file, $data);
- echo 'all done';
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement