0

Hi I am working on a website that users can use to create their own blogs. But I have hit a problem.
Whenever I try to create a new file with the members username in. The rest of my script works perfectly.
Can anyone see a problem with my code.
P.S. the $username value is already specified by a previous form.

//Create User settings
$file = "user.php";
$handle = fopen("$username/$file", "w");
$data = '<?php $userid = "' . $username . '" ?>';
fwrite($handle, $data);
fclose($handle);

Thanks in advance

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ilikesimple
0
//Create User settings
$file = "user.php";
if (!is_dir($username))
 {
 mkdir($username);
 }
$handle = fopen("$username/$file", "w");
$data = '<?php $userid = "' . $username . '" ?>';
fwrite($handle, $data);
fclose($handle);

I used the simplest form of mkdir here but you have to create the directory first, then create the file inside. Thanks for the question, I actually didn't know you couldn't create directories on-the-fly until trying your code out.


David

0
//Create User settings
$file = "user.php";
if (!is_dir($username))
 {
 mkdir($username);
 }
$handle = fopen("$username/$file", "w");
$data = '<?php $userid = "' . $username . '" ?>';
fwrite($handle, $data);
fclose($handle);

I used the simplest form of mkdir here but you have to create the directory first, then create the file inside. Thanks for the question, I actually didn't know you couldn't create directories on-the-fly until trying your code out.


David

Thanks for the reply.
I already had a mkdir slightly higher up in the code.
However what I didn't know was that you couldn't create a file in a directory with a chmod of 700. I changed it to chmod to 744 and its working fine now.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.