Jump to content

Creating Files Dynamically With PHP?


elite_prodigy

Recommended Posts

I think I read about this somewhere, but I can't think how to accomplish it.

 

Can someone tell me the functions, and maybe give me a few examples?

 

I need to be able to create folders(directories) and files dynamically when a user registers.

Link to comment
Share on other sites

<?php
$folder = "/stuff/";
$file = "posting.php";

if(file_exists($folder . $file)){
if(!$_GET['rewrite']){
	echo "This file exists, <a href=\"?rewrite=yes\">click here</a> to over write with a new file!\n";
}else {
	unlink($folder . $file);
	$f = fopen($folder . $file, "w+");
	fclose($f);

	echo $file . " has been created in the folder <b>".$folder."</b>\n";
}
}else {
$f = fopen($folder . $file, "w+");
fclose($f);
echo $file . " has been created in the folder <b>".$folder."</b>\n";
}
?>

 

example.

Link to comment
Share on other sites

Why do you need to create directories and files when a user registers? Much easier to use one file for all users, store there relevent data in a database and use mod_rewrite to give the impression each user has there own directory.

 

this is pretty much the basics of dynamic website creation. Do you think this forum creates a new page everytime someone adds a new thread?

Link to comment
Share on other sites

I'm building a new website for each user. So their site name will be www.somesite.com/their-site-name

 

Thus, I need to create directories and files dynamically upon registration. Unless you have a better method?

 

Please, I'm open to ALL suggestions!

Link to comment
Share on other sites

Thus, I need to create directories and files dynamically upon registration. Unless you have a better method?

 

I just gave you my better method in my last reply. This really is the basics of dynamic website creation.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.