Skip to main content
April 18, 2007
Answered

Dynamic Make Folder Script in PHP

  • April 18, 2007
  • 1 reply
  • 307 views
I have been trying to work on a script where I want to create a folder for a user that I choose. So far the script works if it is static but I want to make it dynamic. Let me show you what I have.

Here is my MySQL for registered users, it is just simple for demo purposes.
CREATE TABLE `register` (
`regID` int(11) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`regID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Now what I have done was make a list of all my registered users and a button called create folder. When I click on that I am able to create a folder for that user.

This is what I have.
--------------------------
// Start insert folder
$makedir = "$row_rsRegGet['regID']";
$targetpath = $_SERVER['DOCUMENT_ROOT'] . "/register/userFile/$makedir/";
$target = $targetpath . basename( $_FILES['uploadedfile']['name']);
mkdir($targetpath.$vName,0700);
// End insert folder

I am getting an error and can't figure out where is my mistake.
This topic has been closed for replies.
Correct answer Newsgroup_User
On Wed, 18 Apr 2007 17:12:20 +0000 (UTC), "AdonaiEchad"
<webforumsuser@macromedia.com> wrote:

>I really do not know what $vName means. I saw this script at a site and it
>works when it is static it is when I use dynamic attributes that it gives me an
>error.
>
> So if $makedir = "$row_rsRegGet['regID']"; was $makedir = "addFolder"; it will
>make a folder within the /register/userFile/addFolder/. The problem lies when
>placing the dynamci I can not seem to get to function.

You still don't say what the error message is. It could be a permissions
issue. However, I do see an error in your code:

$makedir = "$row_rsRegGet['regID']";

You cannot use the single quotes on an array key inside double quotes.
Change the above to:

$makedir = $row_rsRegGet['regID'];

If you modify your code thusly, it should either work and, if it fails,
at least tell you what the directory is that it's trying to create:

$row_rsRegGet['regID']=101;
// Start insert folder
$makedir = $row_rsRegGet['regID'];
$targetdir = "/register/userFile/$makedir";
$targetpath = $_SERVER['DOCUMENT_ROOT'] . $targetdir;
if(mkdir($targetpath,0700)){
print "Created directory $targetdir";
}else{
print "Failed to create $targetdir";
}
// End insert folder

If it fails, supply the error message.

Gary

1 reply

Inspiring
April 18, 2007
On Wed, 18 Apr 2007 04:28:40 +0000 (UTC), "AdonaiEchad"
<webforumsuser@macromedia.com> wrote:

> mkdir($targetpath.$vName,0700);


What's $vName?


> I am getting an error and can't figure out where is my mistake.

What is the error message?

Gary
Newsgroup_UserCorrect answer
Inspiring
April 18, 2007
On Wed, 18 Apr 2007 17:12:20 +0000 (UTC), "AdonaiEchad"
<webforumsuser@macromedia.com> wrote:

>I really do not know what $vName means. I saw this script at a site and it
>works when it is static it is when I use dynamic attributes that it gives me an
>error.
>
> So if $makedir = "$row_rsRegGet['regID']"; was $makedir = "addFolder"; it will
>make a folder within the /register/userFile/addFolder/. The problem lies when
>placing the dynamci I can not seem to get to function.

You still don't say what the error message is. It could be a permissions
issue. However, I do see an error in your code:

$makedir = "$row_rsRegGet['regID']";

You cannot use the single quotes on an array key inside double quotes.
Change the above to:

$makedir = $row_rsRegGet['regID'];

If you modify your code thusly, it should either work and, if it fails,
at least tell you what the directory is that it's trying to create:

$row_rsRegGet['regID']=101;
// Start insert folder
$makedir = $row_rsRegGet['regID'];
$targetdir = "/register/userFile/$makedir";
$targetpath = $_SERVER['DOCUMENT_ROOT'] . $targetdir;
if(mkdir($targetpath,0700)){
print "Created directory $targetdir";
}else{
print "Failed to create $targetdir";
}
// End insert folder

If it fails, supply the error message.

Gary
April 18, 2007
It works perfect now. It was the quotes that messed it up but also the if statement helped very much. Thank you for your help.