Jump to content


Photo

Need some guidance...


  • Please log in to reply
2 replies to this topic

#1 milointeractive

milointeractive
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 July 2006 - 08:14 PM

Hello. I am getting more comfortable with PHP/MySQL in building CMS systems for clients. I want to embark on a new project that requires a bit more expertise. Here is what I am trying to accomplish:

When a user creates a link in their admin area (simple php/mysql add, modify, delete type of system), I need to create a directory based on what they title their link. I would then need two files to be added in the directory (an index file, and a detail file) both of which would need to be dynamically assigned the ID of the recently inserted "link" record.

Can anyone point me in the right direction or include some URLs to some useful information?

Thanks!

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 08:40 PM

Ok what I would do is use
mkdir
to create the directory. And then usen
fopen
to create the files. I would do something like this.

you can create a link to this file like this
<a href="thisfile.php?var=$var">Add your Var</a>

<?php
$var = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord($0).";"', $var);

if (!$var) {
    echo "You did not enter a variable";
    include('yourform.php');
    exit;
}
$dir = "path/to/new/dir/$var";
mkdir("$dir", 0700);

if (!mkdir) {
    echo "unable to create the directory. You may not have to proper permissions to do so";
    include('yourform.php');
    exit;
}
//the index.php
$filename = "$dir/index.php";
$somecontent = "<?php
echo \"You sucessfuly created the index.php\"
?>";	 	
$handle = fopen($filename, "x+");
fwrite($handle, $somecontent);
fclose($handle);

//now the detail
$file = "$dir/details.php";
$content = "<?php
echo \"You sucessfuly created the details.php\"
?>";	 	
$h = fopen($file, "x+");
fwrite($h, $content);
fclose($h);
?>


Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 milointeractive

milointeractive
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 July 2006 - 10:57 PM

Tom -- Excellent! Thanks so much for the reply! I am going to see what I can put together!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users