Jump to content

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/15831-need-some-guidance/
Share on other sites

Ok what I would do is use [code=php:0]mkdir[/code] to create the directory. And then usen [code=php:0]fopen[/code] to create the files. I would do something like this.

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

[code=php:0]<?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);
?>[/code]

Hope this helps,
Tom
Link to comment
https://forums.phpfreaks.com/topic/15831-need-some-guidance/#findComment-64812
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.