Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic Make Folder Script in PHP

Guest
Apr 17, 2007 Apr 17, 2007
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.
TOPICS
Server side applications
309
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 18, 2007 Apr 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 s...
Translate
LEGEND ,
Apr 17, 2007 Apr 17, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 18, 2007 Apr 18, 2007
Here is the same code but a lot more simpler...
$makedir = "newFolder";
$mypath = $_SERVER['DOCUMENT_ROOT'] . "/register/userFile/$makedir/";
mkdir($mypath,0777,TRUE);

The thing is I am still getting an error when I place the $makedir = "newFolder"; in a dynamic such as $makedir = "$row_rsRegGet['regID']"; how can I get the dynamic to accept.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2007 Apr 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 18, 2007 Apr 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2007 Apr 18, 2007
LATEST
On Wed, 18 Apr 2007 20:12:18 +0000 (UTC), "AdonaiEchad"
<webforumsuser@macromedia.com> wrote:

>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.

You're welcome. Glad it helped.

Gary
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines