Writing a .php extension

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
Mobius Man
Forum Newbie
Posts: 8
Joined: Mon Dec 15, 2003 8:16 pm

Writing a .php extension

Post by Mobius Man »

I have a simple fwrite script to create new pages with. However, those new pages always never have an extension, so I have to manually change it. How can I have it write an extension (I only need .php) to those files I've created.

Code: Select all

<?php
include ("news/config.php");
$id = $_POST["id"];
$section = $_POST["section"]; //Use for later
$date = date("F j, Y");
$name = $_POST["name"];
$email = $_POST["email"];
$title = $_POST["title"];
$content = $_POST["content"];
$pass = $_POST["password"];

if ($password == $pass)
{



$filename = 'articles.php';


$file = file_get_contents($filename);
$fp = fopen($filename, "w");
fwrite($fp, "<a href=index.php?page=articles&id=$id>$title</a> - $date <br /><br />");
fwrite($fp, $file);
fclose($fp);



chdir($section);

$file = file_get_contents($id);
$fp = fopen($id, "w");
fwrite($fp, "<h1>$title</h1> Posted by: <a href=mailto:$email>$name</a>  $date <br /><br /><br /><br /> $content</font> <br />");


fwrite($fp, $file);

fclose($fp);
?>
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

try:

Code: Select all

<?php 
include ("news/config.php"); 
$id = $_POST["id"]; 
$section = $_POST["section"]; //Use for later 
$date = date("F j, Y"); 
$name = $_POST["name"]; 
$email = $_POST["email"]; 
$title = $_POST["title"]; 
$content = $_POST["content"]; 
$pass = $_POST["password"]; 

if ($password == $pass) 
{ 



$filename = 'articles.php'; 


$file = file_get_contents($filename); 
$fp = fopen($filename, "w"); 
fwrite($fp, "<a href=index.php?page=articles&id=$id>$title</a> - $date <br /><br />"); 
fwrite($fp, $file); 
fclose($fp); 



chdir($section); 

$file = file_get_contents($id); 
$fp = fopen($id.php, "w"); 
fwrite($fp, "<h1>$title</h1> Posted by: <a href=mailto:$email>$name</a>  $date <br /><br /><br /><br /> $content</font> <br />"); 


fwrite($fp, $file); 

fclose($fp); 
?>
Post Reply