Page 1 of 1

Php mkdir

Posted: Mon Dec 21, 2009 4:55 pm
by hero789
Hi
This is an excerpt from my php file. I am trying to create directories using the users first name as a test. The directory is created but it is called $nfirstname. Does anyone know how I can change the mkdir line to ensure that the variable content is used to name the directory rather than this.

Code: Select all

<?php
if (isset ($_POST['submit']))
    {
 
$ntitle = $_POST['title'];
$nfirstname = $_POST['first_name'];
$nlastname = $_POST['last_name'];
 
mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\$nfirstname\inbox');
mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\$nfirstname\outbox');
//posted elements displayed back to screen
 
$nhouse_number = $_POST['house_number'];
$nstreet = $_POST ['street'];

Re: Php mkdir

Posted: Mon Dec 21, 2009 5:16 pm
by AbraCadaver

Re: Php mkdir

Posted: Mon Dec 21, 2009 5:25 pm
by hero789
thanks

Re: Php mkdir

Posted: Mon Dec 21, 2009 6:03 pm
by daedalus__
hero you've posted like five threads in the past two days but haven't used code tags in any of them. could you do that?

[syntax=php]$msg = "code tags are good for your health";

echo $msg;[/syntax]

like that

Re: Php mkdir

Posted: Mon Dec 21, 2009 6:53 pm
by jd6th
your code should be like this....

Code: Select all

mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\[b]'.$nfirstname.'[/b]\inbox');
mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\[b]'.$nfirstname.'[/b]\outbox');
or use double quote... on the file path...

Code: Select all

mkdir($_SERVER['DOCUMENT_ROOT'].[b]"\project\website\admin\trainer\$nfirstname\inbox"[/b]);
mkdir($_SERVER['DOCUMENT_ROOT'].[b]"\project\website\admin\trainer\$nfirstname\outbox"[/b]);

Re: Php mkdir

Posted: Mon Dec 21, 2009 7:07 pm
by hero789
Hi Shawn

Thanks for your help. Managed to get it to work. Used the following:-

Code: Select all

$ntrainer_id = $_POST['trainer_id'];
$ntitle = $_POST['title'];
$nfirstname = $_POST['first_name'];
$nlastname = $_POST['last_name'];
 
$fullname = "$nfirstname$nlastname";
mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\\'."$fullname".'\inbox', 0700, true);
mkdir($_SERVER['DOCUMENT_ROOT'].'\project\website\admin\trainer\\'."$fullname".'\outbox', 0700, true);

Re: Php mkdir

Posted: Mon Dec 21, 2009 7:12 pm
by s.dot
Please use [ code ]code here[ /code ] and [ code=php ]php code here[ /code ] to post code and php code, respectively. I have edited your posts to reflect how we would like you to post code snippets.