Link to home
Start Free TrialLog in
Avatar of weikelbob
weikelbobFlag for United States of America

asked on

generating files out of code

How do I take a bunch of html/php code and make a file that contains only that code?
Avatar of markdoc
markdoc

hi, where exactly do you get these html/php code?
do you get them from other files, etc?
Avatar of weikelbob

ASKER

I'm auto-generating websites. They get a folder on the server. They fill out the forms and it needs to upload each php page to their folder. If they only fill out 5 pages, their folder would end up with 5 files, a 5-page website. I'm storing the information, like title, background color, text color, etc. in a MySQL database. Each page can be made from a html page with php inserting the title, background, etc. but I don't know how to dynamically place the files onto the server. All of it should be done without me (automatically)

SOLUTION
Avatar of markdoc
markdoc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My script won't make a directory:
I've cmoded users to 777:

<?php
include('includeme.php');

$_SESSION['username']="weikelbob@aol.com";
## so maybe you load a template:
$s = file_get_contents('page1.html');
## file_get_contents requires PHP >= 4.3

## then replace a few things using the form data:
$s = str_replace("%1title1%", $_SESSION['title'], $s);

  $query ="SELECT id FROM customer1 WHERE email= '" . $_SESSION['username'] . "'";
  $result = mysql_query ($query);
  $row = mysql_fetch_array($result);

## create the directory for the user
$dir = '/users/' . $row['id'];
mkdir($dir,0707);

## now create filename for user's home page
$filename = $dir.'/index.html';

## dump contents of $s to the file
ignore_user_abort(true);          ## prevent refresh/stop from screwing up file operations
$fh = @fopen($filename, 'w');
if ($fh)
{
     fwrite($fh, $s);
     fclose($fh);
} else
{
     ## handle file error here
}
ignore_user_abort(false);

## let 'em know where to go
$url = 'http://www.editable-over-time/users/' . $row['id'];
echo 'Your new home page is at <a href="'.$url.'">'.$url.'</a>';

?>
can you do a test of just mkdir? something like:

<?php

mkdir('/full/path/to/users/test',0777);

?>
It doesn't work. My domain is editable-over-time.com. I have a directory named users. I ran the following and nothing happened:

<?php

mkdir('/users/test',0777);

?>
I'm wondering about the directory you're trying, "/users/test". Most webservers only serve files out of some subdirectory and it would be unusual to serve web pages from a "users" directory off the root directory. I would expect the directory to be more like "/usr/www/users/test". Are you on a shared webserver? If so, then I'm almost sure that directory path is incomplete. Here's how you can find out...

Make a file called phpinfo.php with just this:
<?php
phpinfo();
?>

Put it in your "users" directory and call it up in a web browser. You should see all your PHP configuration info. Scroll down to see the value for SCRIPT_FILENAME. You should be using a path similar to what you see there, except that the "phpinfo.php" at the end will be replaced by "test" or a user name. Let me know how that works out.

FYI...you left out the ".com" from
$url = 'http://www.editable-over-time/users/' . $row['id'];

Thanks merwetta, the phpinfo() showed me the real directory path.