Page 1 of 1

How to create new pages automatically from a form with PHP ?

Posted: Sat Jan 19, 2008 3:13 am
by Toxinhead
Hey there guys!
I was just wondering how would i go about making automated image portal that when you fill out a form and upload your picture to the database, it creates a new page from a template and includes that picture within it?

I know the basics of php and mysql but don't know how to automatically make a new .html or .php from a template and include that uploaded picture on submit?

Thanks HEAPS in advance!
Ricky

Re: How to create new pages automatically from a form with PHP ?

Posted: Sat Jan 19, 2008 3:53 pm
by Jonah Bron
Hello, Toxinhead.

here's what you want:


Template page(template.html)

Code: Select all

<html>
<head>
<title>Dynamicly made page</title>
</head>
<body>
<div>
the picture is below!<br />
<!_!_!_!_PIC GOES HERE_!_!_!_!>
</div>
</body>
</html>
PHP for dynamicly made page:

Code: Select all

<?php
//upload pic and save it to a location
$pic = 'pic location';
 
$template = file_get_contents('template.html');//get template
$template = explode('<!_!_!_!_PIC GOES HERE_!_!_!_!>', $template);//breakup template at specified point
$template = $template[0] .'<img src="'. $pic .'" />'. $template[1];// add <img> tag to template, and implode all in one
 
fwrite(fopen('new_page.html', 'w'), $template) or die('Couldn\'t make page');//write content to new page, in "w" mode, to make a new one
echo 'Page made successfully';
?>