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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Toxinhead
Forum Newbie
Posts: 3
Joined: Sat Jan 19, 2008 3:12 am

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

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post 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';
?>
Post Reply