PHP file and/or directory creation trouble

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:


//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)

Error: You must complete all required fields.


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 SUBMISSION\n”);

//get and write user’s details
$usrip = $_SERVER[‘REMOTE_ADDR’];
$tdate = gmdate(DATE_RFC822);
fwrite($file, "Recieved: " . $tdate . "; " . $usrip . "; " . $alias . “\n-------------------------\n\n”);


[/code]If somebody sees something wrong, please help me out.

What is the error message you are getting?

si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]

Usually I get something like this when I try it.
function.fopen]: failed to open stream: No such file or directory

I do notice that when it creates the directory the permissions look different (it says rwx------ and the rest of the directories show rwxr-xr-x, sorry I don’t know much about chmoding so I don’t know if this is a problem or not, but I think the program would be considered the owner, and therefor have access no matter what).

If it cannot find the file, try using a relative path.

si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]

I think that already is the relative path. It’s layed out like this…
|-a directory
|–the directory we are creating
|–the file that creates the directory above

So from the file creating the directory, the path would start out with the name of the directory, right?
$file = fopen("/$alias/display.txt", “w+”);//create file

Is there another way that I don’t know about?

Do a print of $alias and verify it is correct. Also you may need to use period in the directory.



My website

That works. Thank you both for your help. I really appreciate it.