PHP - File Write

Status
Not open for further replies.

Livar

Now 35% cooler!
Oct 15, 2010
846
86
Hey there, well I've been trying to make an installer, just can't get my head around what to write:

Here's my current code,
PHP:
<?php
/* ----------------------------------------
 * LEEXOWEB - CONTENT MANAGMENT SYSTEM
 * COMPATIBLE WITH UBEREMULATOR (PHOENIX)
 * ----------------------------------------
 * AUTHOR: LIVAR SHEKHANI (POWAHALERT)
 * AUTHOR: WWW.L-SHEKHANI.CO.UK
 * -------------------------------------- */

//Security reasons
DEFINE('SECURITY', true);

//Check if the configuration actually exists
if(!file_exists('../includes/configuration.php'))
{
    Header("Location: /index.php");
}

//Or define the installer
DEFINE('INSTALLER', true);

//Install function
if(isset($_POST['hotel_name']))
{
    $MySQL_Host = $_POST['MySQL_Host'];
    $MySQL_User = $_POST['MySQL_User'];
    $MySQL_Pass = $_POST['MySQL_Pass'];
    $MySQL_Data = $_POST['MySQL_Data'];
    
    $Hotel_Url = $_POST['Hotel_Url'];
    $Hotel_Name = $_POST['Hotel_Name'];
    
    $InstallName = './includes/configuration.php';
    $InstallOpen = fopen($InstallName, 'w');
    fwrite($InstallOpen, 'here now');
    fclose($InstallOpen); 
}

?>
<html>
    <head>
        <title>LeexoWEB - Installer</title>
        <link rel="stylesheet" href="style/style.css" type="text/css" />
    </head>
<body>
    <div id="Header">
        <div class="Content">LeexoWEB - Installer</div>
    </div> 
        
    <br>
    <div id="Box">
        <center><h1>Welcome!</h1>
            <br>Hello there, and welcome to LeexoWEB's own installer, nice isn't it? LeexoWEB is a Content Management System which was made by <b>Livar Shekhani</b>, I have really tried to put 'effort' into this CMS, so please make the use of this System. The reason you have been redirected here is because your Configuration file does not exist, so this page will show you how to install it!
            <br>
            <br>Please make a new .PHP file called 'configuration' and put it into your 'includes' folder, with the contents of this:
            <br> 
            <br>
            <textarea class="paste">
/* ----------------------------------------
 * LEEXOWEB - CONTENT MANAGMENT SYSTEM
 * COMPATIBLE WITH UBEREMULATOR (PHOENIX)
 * ----------------------------------------
 * AUTHOR: LIVAR SHEKHANI (POWAHALERT)
 * AUTHOR: WWW.L-SHEKHANI.CO.UK
 * --------------------------------------*/

//Database variables
$Database['mysql']['hostname'] = 'HOST';
$Database['mysql']['username'] = 'USERNAME';
$Database['mysql']['password'] = 'PASSWORD';
$Database['mysql']['database'] = 'DATABASE';

//System variables
$System['host']['url'] = 'HOTEL URL';
$System['hotel']['name'] = 'HOTEL NAME';
$System['password']['secret_hash'] = 'bgdu!"**"£$%^N/,illeexoUdvdabohr%dv';


</textarea>
    </div>
        
        
        
</body>

but I wan't to make it as a click of a button, but how can I make the file write function write this:

PHP:
/* ----------------------------------------
 * LEEXOWEB - CONTENT MANAGMENT SYSTEM
 * COMPATIBLE WITH UBEREMULATOR (PHOENIX)
 * ----------------------------------------
 * AUTHOR: LIVAR SHEKHANI (POWAHALERT)
 * AUTHOR: WWW.L-SHEKHANI.CO.UK
 * --------------------------------------*/

//Database variables
$Database['mysql']['hostname'] = 'HOST';
$Database['mysql']['username'] = 'USERNAME';
$Database['mysql']['password'] = 'PASSWORD';
$Database['mysql']['database'] = 'DATABASE';

//System variables
$System['host']['url'] = 'HOTEL URL';
$System['hotel']['name'] = 'HOTEL NAME';
$System['password']['secret_hash'] = 'bgdu!"**"£$%^N/,illeexoUdvdabohr%dv';
the issue is, it's to big for the fwrite, any chance i can do it in a variable or.....
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
I never tested it so I'm not sure if it will work as you want it to, but try this:

PHP:
<?php
$file_to_create = "config.php";
 
$data_to_write = "/* ----------------------------------------";
$data_to_write .= " * LEEXOWEB - CONTENT MANAGMENT SYSTEM";
$data_to_write .= " * COMPATIBLE WITH UBEREMULATOR (PHOENIX)";
$data_to_write .= " * ----------------------------------------";
$data_to_write .= " * AUTHOR: LIVAR SHEKHANI (POWAHALERT)";
$data_to_write .= " * AUTHOR: WWW.L-SHEKHANI.CO.UK";
$data_to_write .= " * --------------------------------------*/";
$data_to_write .= "";
$data_to_write .= "//Database variables";
$data_to_write .= '$Database[\'mysql\'][\'hostname\'] = \'HOST\';';
$data_to_write .= '$Database[\'mysql\'][\'username\'] = \'USERNAME\';';
$data_to_write .= '$Database[\'mysql\'][\'password\'] = \'PASSWORD\';';
$data_to_write .= '$Database[\'mysql\'][\'database\'] = \'DATABASE\';';
$data_to_write .= "";
$data_to_write .= "//System variables";
$data_to_write .= '$System[\'host\'][\'url\'] = \'HOTEL URL\';';
$data_to_write .= '$System[\'hotel\'][\'name\'] = \'HOTEL NAME\';';
$data_to_write .= '$System[\'password\'][\'secret_hash\'] = \'bgdu!"**"£$%^N/,illeexoUdvdabohr%dv\';';
 
$createfile = fopen( $file_to_create, "w" ); //create file "config.php"
 
fwrite( $data_to_write, $createfile );
 
//$file_to_create has been created and written to!
 
fclose( $createfile );
?>
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
Absolutely nothing, here's my current code:

PHP:
<?php
/* ----------------------------------------
 * LEEXOWEB - CONTENT MANAGMENT SYSTEM
 * COMPATIBLE WITH UBEREMULATOR (PHOENIX)
 * ----------------------------------------
 * AUTHOR: LIVAR SHEKHANI (POWAHALERT)
 * AUTHOR: WWW.L-SHEKHANI.CO.UK
 * -------------------------------------- */

//Security reasons
DEFINE('SECURITY', true);

//Check if the configuration actually exists
if(!file_exists('../includes/configuration.php'))
{
    Header("Location: /index.php");
}

//Or define the installer
DEFINE('INSTALLER', true);

//Install function
if(isset($_POST['Hotel_Name']))
{
    $MySQL_Host = $_POST['MySQL_Host'];
    $MySQL_User = $_POST['MySQL_User'];
    $MySQL_Pass = $_POST['MySQL_Pass'];
    $MySQL_Data = $_POST['MySQL_Data'];
    
    $Hotel_Url = $_POST['Hotel_Url'];
    $Hotel_Name = $_POST['Hotel_Name'];
    
    $InstallName = '../includes/configuration.php';
    $InstallOpen = fopen($InstallName, 'w');
    $data_to_write = "/* ----------------------------------------";
    $data_to_write .= " * LEEXOWEB - CONTENT MANAGMENT SYSTEM";
    $data_to_write .= " * COMPATIBLE WITH UBEREMULATOR (PHOENIX)";
    $data_to_write .= " * ----------------------------------------";
    $data_to_write .= " * AUTHOR: LIVAR SHEKHANI (POWAHALERT)";
    $data_to_write .= " * AUTHOR: WWW.L-SHEKHANI.CO.UK";
    $data_to_write .= " * --------------------------------------*/";
    $data_to_write .= "";
    $data_to_write .= "//Database variables";
    $data_to_write .= '$Database[\'mysql\'][\'hostname\'] = \'HOST\';';
    $data_to_write .= '$Database[\'mysql\'][\'username\'] = \'USERNAME\';';
    $data_to_write .= '$Database[\'mysql\'][\'password\'] = \'PASSWORD\';';
    $data_to_write .= '$Database[\'mysql\'][\'database\'] = \'DATABASE\';';
    $data_to_write .= "";
    $data_to_write .= "//System variables";
    $data_to_write .= '$System[\'host\'][\'url\'] = \'HOTEL URL\';';
    $data_to_write .= '$System[\'hotel\'][\'name\'] = \'HOTEL NAME\';';
    $data_to_write .= '$System[\'password\'][\'secret_hash\'] = \'bgdu!"**"£$%^N/,illeexoUdvdabohr%dv\';';
    fwrite($data_to_write, $InstallOpen);
    fclose($InstallOpen); 
}

?>
<html>
    <head>
        <title>LeexoWEB - Installer</title>
        <link rel="stylesheet" href="style/style.css" type="text/css" />
    </head>
<body>
    <div id="Header">
        <div class="Content">LeexoWEB - Installer</div>
    </div> 
        
    <br>
    <div id="Box">
        <center><h1>Welcome!</h1>
            <br>Hello there, and welcome to LeexoWEB's own installer, nice isn't it? LeexoWEB is a Content Management System which was made by <b>Livar Shekhani</b>, I have really tried to put 'effort' into this CMS, so please make the use of this System. The reason you have been redirected here is because your Configuration file does not exist, so this page will show you how to install it!
            <br>
            <br>Please enter the details below!
            
            <br>
                    <form method="post">
                            
                MySQL Host: <input type="text" name="MySQL_Host" id="password" />
                                <br>
                                MySQL User: <input type="text" name="MySQL_User" id="password" />
                                <br>
                                MySQL Pass: <input type="text" name="MySQL_Pass" id="password" />
                                <br>
                                MySQL Database: <input type="text" name="MySQL_Data" id="password" />
                                <br>
                                Hotel URL: <input type="text" name="Hotel_Url" id="password" />
                                <br>
                                Hotel Name: <input type="text" name="Hotel_Name" id="password" />
                               

                <input type="submit" value="Install!" name="Login" />
                </form>
             
           
    </div>
        
        
        
</body>
</html>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
Just for testing purposes, remove all lines of '$data_to_write' except the first one and put something like "test 123" or something, then execute your code just to see if it works.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
Change
PHP:
if(isset($_POST['Hotel_Name']))
to
PHP:
if(isset($_POST['Login']))

Because if 'Hotel_Name' doesn't have a value, it won't execute the code, so you want to change it to your Login button, which does have a value.

Anyway, try this:

PHP:
$open = fopen( "../includes/configuration.php", "w" );
fwrite( "Hello", $open );
fclose( $open);

Try that. Remove all the other stuff you have and replace it with that, then retry.
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
No cigar:

PHP:
if(isset($_POST['Install']))
{
    $open = fopen("../includes/configuration.php", "w");
    fwrite("Hello", $open);
    fclose($open);
}

Finally got it to write, thanks!
 
Status
Not open for further replies.

Users who are viewing this thread

Top