0

Hello folks!

Is it possible to create directories on my web server based on new database entries?

I am implementing a photo gallery and want to have it such that, when a user ADDS a new Gallery, a (sub)directory is created with the name that the user gave the gallery. Then when the user uploads photos into that gallery, they are actually stored in the corresponding folder.

Help, anyone?

Thanks so much in advance!

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Stefano Mtangoo
0

Yes.

From the php manual:

mkdir("/path/to/my/dir", 0700);

http://www.php.net/manual/en/

OR download from:

http://www.php.net/download-docs.php

Just quickly: you need to ensure that the folder doesn't have any illegal characters - so naming a folder after the username probably isn't a good idea. Calling it member_XXXX (where XXXX = the member's id, which should be an integer, should be safe).

You probably need a user folder in case duplicate gallery names are created by different users. Otherwise, you can use "gallery_XXXX" as in the previous example. This, again is to prevent weird folder names.

The only problem with this approach is that photos can't be shared across galleries unless the files are copied.

Why not have uploaded files renamed to the id value (photo id) value in the DB? The DB can store a "false" filename that is just used for reference purposes, e.g. the photo table:

id ** (146278)
photo_name
photo_description
uploader_id
uploaded_date
snapped_date
photo_falsefilename ** (hefty_elephant)
photo_extension** (jpg)

The photo will be known as hefty_elephant.jpg, but stored as 146278.jpg

This means that ALL photos can be stored in an uploads folder - ALL photos from ALL users, that is. It even means that photos could have duplicate falsefilenames, but it wouldn't matter because all files are stored as their 'id' values.

Just one of many ways you could create your gallery site.

Edited by diafol: n/a

0

Hello folks!

Is it possible to create directories on my web server based on new database entries?

Sure, very possible!

Hello folks!I am implementing a photo gallery and want to have it such that, when a user ADDS a new Gallery, a (sub)directory is created with the name that the user gave the gallery. Then when the user uploads photos into that gallery, they are actually stored in the corresponding folder.

Just query database names or whatever and assign it to a variable. Then pass it as an argument to PHP function for making DIRs

Thanks so much in advance!

You are welcome ;)

0

Yes.

From the php manual:

mkdir("/path/to/my/dir", 0700);

http://www.php.net/manual/en/

OR download from:

http://www.php.net/download-docs.php

Just quickly: you need to ensure that the folder doesn't have any illegal characters - so naming a folder after the username probably isn't a good idea. Calling it member_XXXX (where XXXX = the member's id, which should be an integer, should be safe).

Thanks, ardav! I thought there might be potential problems with using the user-defined name! Using an integer is a great idea!
This won't be tied to multiple users, just one administrator of the entire site, so there is no "member id"- maybe I'll go with the gallery id. Thanks again.

0

Sorry sadie - I edited while you replied - hope you got the rest of my post!

Yes, ardav, I did. Thank you so much. I will keep your suggestion in my "toolbox" for another upcoming project that will involve multiple users so I can still use this!

Much appreciated, ardav and evstevemd!
:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.