Gossamer Forum
Home : Products : DBMan : Customization :

create directory for each users

Quote Reply
create directory for each users
I would like to create a new directory for each user after the have successfully added a record to the database (I will use this to put image file in.

Within the add success sub mod I've tried many versions of:

{mkdir $main_path $rec{'userid'}}

None are working ... any ideas?
Quote Reply
Re: create directory for each users In reply to
I've never used mkdir, but I would presume that the syntax would be more like:

mkdir("$mainpath/$rec{'userid'}");

or:

mkdir "$mainpath/$rec{'userid'}";

These would asssume that $mainpath is something like "/path/to/storage/dir".

Cheers,
adam
Quote Reply
Re: create directory for each users In reply to
Hmmm... Not too sure about them now I look at 'em. Try the first one without the quotes. Oh buggrit, I'll try it meself and come back to you...

*sheesh* Smile

adam
Quote Reply
Re: create directory for each users In reply to
I continue to get a "not enough arguments"
error
Quote Reply
Re: create directory for each users In reply to
Ah! You have to set permissions on the directory while you're at it. I presumed it would set them to 644 by default. This got it for me anyway:

mkdir ("$main_path/$rec{'userid'}", "0644");

Cheers,
adam
Quote Reply
Re: create directory for each users In reply to
Well I've gotten it to work if I hard code the userid. Unfortunately it does not pull in the userid any ideas why?

Here's my code:


$main_path ='../usrupld';
sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

$page_title = "Record Added";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following record was successfully added to e.ternity:</FONT>
|;
# < -- End page text -->

&html_record(&get_record($in{$db_key}));
mkdir("$main_path/$rec{'userid'}",0666);
chmod(703, "$main_path/$rec{'userid'}");

&html_footer;
&html_page_bottom;
}
Quote Reply
Re: create directory for each users In reply to
I used $db_userid and it worked like a charm...don't know why though
Quote Reply
Re: create directory for each users In reply to
The reason $rec{'userid'} didn't work is the following:

When you use

&html_record(&get_record($in{$db_key}));

The argument for the subroutine
&get_record($in{$db_key})

is passed and placed into the %rec hash in html_record. However, the %rec hash is a "my" variable. It only applies to the subroutine. At the point that the script comes back to html_add_success, the script has "forgotten" the value of the %rec hash.


------------------
JPD





Quote Reply
Re: create directory for each users In reply to
Well, if it ain't broke, don't fix it! The reason you couldn't get it though was because the %rec array isn't available to the subroutine. But you should be able to get it with the %in array:

mkdir("$main_path/$in{'userid'}",0666);

One other point, I notice you're using chmod after you created the directory. I don't think there's any need to do that, you're already setting it to 0666 in mkdir. So if you want to chmod the dir 703, why not do this:

mkdir("$main_path/$in{'userid'}",0703);

Cheers,
adam
Quote Reply
Re: create directory for each users In reply to
Is this really the best approach? What I would recommend is just having a central images directory, and then save the image as ID number.gif or something unique. Making a directory just to store a single image seems like a lot of extra work. =)

Cheers,

Alex