Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function create_config($path,$server,$db_name)
  2. {
  3. global $user, $user_pass;
  4. $string_config = <<<EOD
  5. <?php
  6.  
  7. $CFG = array(
  8. 'host'=> '$server',
  9. 'database' => '$db_name',
  10. 'user' => '$user',
  11. 'password' => '$user_pass'
  12. );
  13. ORM::configure(array(
  14. 'connection_string' => 'mysql:host='.$CFG['host'].';dbname='.$CFG['database'],
  15. 'username' => $CFG['user'],
  16. 'password' => $CFG['password'],
  17. 'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND=>'set NAMES utf8')));
  18. EOD;
  19.  
  20. try
  21. {
  22. touch("../../$path"); //Creo la ruta en la raiz del fichero mkdir
  23. $fh = fopen("../../$path","w+") or die("Error al crear el fichero de configuracion"); //Abro el fichero en mode de escritura
  24. fwrite($fh,$string_config); //escribo en el fichero
  25. fclose($fh); //cierro el fichero
  26. chmod("../../".$path,'0777');#Cambiando permisos
  27. $create_file = true;
  28.  
  29. } catch (PDOException $e)
  30. {
  31. die('error al crear el archivo'.$path."".$e->getMessage());
  32. }
  33. return $create_file;
  34. }
  35.  
  36. if(isset($_POST['instalar']))
  37. {
  38. $server = test_input($_POST['servidor']); //Nombre del servidor
  39. $db_name = test_input($_POST['dbname']);
  40. $user = test_input($_POST['user']);
  41. $user_pass = test_input($_POST['password0']);
  42.  
  43. #Crear el archivo config.php si no existe en caso de que no exista
  44. if(!file_exists("../../".$path))
  45. {
  46. $create_file = create_config($path,$server,$db_name);
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement