Php mkdir

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hero789
Forum Newbie
Posts: 23
Joined: Sun Dec 20, 2009 5:10 pm

Php mkdir

Post 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'];
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Php mkdir

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
hero789
Forum Newbie
Posts: 23
Joined: Sun Dec 20, 2009 5:10 pm

Re: Php mkdir

Post by hero789 »

thanks
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Php mkdir

Post 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
jd6th
Forum Newbie
Posts: 7
Joined: Fri Dec 11, 2009 1:50 am

Re: Php mkdir

Post 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]);
hero789
Forum Newbie
Posts: 23
Joined: Sun Dec 20, 2009 5:10 pm

Re: Php mkdir

Post 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);
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Php mkdir

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply