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

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.