PHP file and/or directory creation trouble
Posted by: username
Posted on: 2007-05-22 15:44:00
I'm not sure if I am going wrong in creating the directory or the file. Usually the error message seems to be concerning the txt file.
Here is a simplified version of my script:
<?php
//get form fields from previous page
$alias = trim($_POST["alias"]);//account for spaces
$search = addcslashes($_POST["searchterms"], '"');
$agree = $_POST["agreement"];
//check required fields
if($agree == NULL || $alias == NULL || $search == NULL)
{
die('<h1>Error: You must complete all required fields.</h1></p>');
}
if(!is_dir($alias))
{
mkdir("$alias", 0700);//create the directory
}
$file = fopen("/$alias/display.txt", "w+");//create file
if(!$file)//check if previous step failed
{
die("Error creating profile content.");
}
$chmod = chmod("/$alias/display.txt", 0755);//set permissions
if(!$chmod)//check if failed
{
die("Error creating permissions for profile.");
}
fwrite($file, "NEW PROFILE SUBMISSIONn");
//get and write user's details
$usrip = $_SERVER['REMOTE_ADDR'];
$tdate = gmdate(DATE_RFC822);
fwrite($file, "Recieved: " . $tdate . "; " . $usrip . "; " . $alias . "n-------------------------nn");
fclose($file);
?>
If somebody sees something wrong, please help me out.