Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2013, 10:07 PM   PM User | #1
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
How to create folder?

How would you create a folder for user files when the user registers? It requires the $_FILE(S?) global variable correct?
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 02-25-2013, 10:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Nope. You issue a mkdir.
Although the worth is questionable. You'd be better off tracking data within the database and using your own directories which could be logically partitioned if you need them to be (filesystems used to have quite a low limitation on the number of files per directory, so we'd split them up based on names and user ids).
Although if everything is grouped by a single user, it does make deletions easier. So I guess that would be a pro for that.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-25-2013, 10:43 PM   PM User | #3
xiong_ster123
New Coder

 
Join Date: Jan 2011
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
xiong_ster123 is an unknown quantity at this point
This is your solution. What this code is doing is finding if the folder "DESIREDFOLDER" folder exists on your server; if not, it will create one for you; if so, it will not do anything. Also, change "DESIREDFOLDER" do your desired folder name. Have fun.

PHP Code:
<?
    $dirname 
$_POST["DirectoryName"];
    
$filename = ("/home/site/public_html/DESIREDFOLDER/");
 
    if (
file_exists($filename)) {
        echo 
"";
    } else {
        
mkdir("/home/site/public_html/DESIREDFOLDER/"0777);
        echo 
"";
    }
?>
xiong_ster123 is offline   Reply With Quote
Old 02-26-2013, 10:07 AM   PM User | #4
alemcherry
New Coder

 
Join Date: Apr 2010
Posts: 55
Thanks: 0
Thanked 4 Times in 4 Posts
alemcherry is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Nope. You issue a mkdir.
Although the worth is questionable. You'd be better off tracking data within the database and using your own directories which could be logically partitioned if you need them to be
That is it. Make directories based on a better logic based on the users you have and amount of files you are expecting to store. It will also be a secure solution, otherwise anyone who know the userame could access all the files. Refer all files stored in the database and use random names for stored files.
__________________
Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon
alemcherry is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.