RhysAndrews Posted December 23, 2008 Share Posted December 23, 2008 Hey guys! I'm using a Windows based server, and my client wishes to have a website in which she can: - Register users / remove / modify / send new password - Give each user a private directory where she can upload new photos to the directory for the users to view via an ajax script I have setup the SQL Database and users can now be registered. I have set up the system so that there is a 'defuser' directory with a template document / the ajax scripts for the photo gallery - then, when a client is registered, 'defuser' is duplicated and renamed as the clients username. So for instance, I register "pooface" and a clone of 'defuser' is created, named "pooface". I have got this working no problem. The issue I have is that I only want this directory (including all the pages and photos) viewable if the browser is logged in as the client who owns that directory. It is important that the photos are protected and unviewable unless logged in as the client who is authorised to view them. Could you help me out? I am brand spanking new to PHP and MySQL but not to programming, and I'm enjoying every step... Regards Rhys Andrews Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/ Share on other sites More sharing options...
MadTechie Posted December 23, 2008 Share Posted December 23, 2008 Okay windows server can not used chown etc.. are you using IIS or apache? as you could create a .htaccess file to protect the folder.. if your not then your best options is probably to have the folders outside the public domain IE c:/htdoc/public_html/ <--HTML stuff (website root) c:/htdoc/private/John <--Johns folder Now as those files are not publically accessible your need to create a script to list & get the files the good thing about this is you can check the logged in users details and check to see if thats their folder very quick example <?php $username = "John"; $dir = "c:/htdoc/private/$username"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } } ?> Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-721942 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Second time today..... Sorry, but I kinda get a bit tired of explaining this simple concept. Here's a similar thread I replied to earlier. The idea of creating an actual script for each user defeats the purpose of writting dynamic webpages IMO. Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-721949 Share on other sites More sharing options...
RhysAndrews Posted December 23, 2008 Author Share Posted December 23, 2008 Hi guys Thanks for your help. The reason I am having a separate directory for each user is because each user has his/her own group of photos that need to be stored together. I could just have 1 private page that changes dynamically according to who is logged in, but I am using an Ajax photo gallery which automatically looks for photos in the /photos directory - in saying that, I could maybe figure out how to alter that so it looks for the ../private/$username directory which incorporates the advice from both of you. Thanks! PS: I think I use Apache; in the Cpanel I have: Apache version 2.2.6 (Unix) Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-722020 Share on other sites More sharing options...
RhysAndrews Posted December 23, 2008 Author Share Posted December 23, 2008 Ok, I've tried to use mkdir to create a directory for the username (this is where photos will be stored), however there is no directory being created even though the function is returning 1. $dirsuccess = mkdir("../../private/$newemail",0600); Is this correct? -Rhys Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-722024 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Mode is ignored by windows so you can leave out the second argument. Are you sure you have permssions to create directories two directories up from where the script is executing? Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-722026 Share on other sites More sharing options...
RhysAndrews Posted December 23, 2008 Author Share Posted December 23, 2008 I probably don't, you know. I can view them when I log into FTP, and create dir's etc via there, but that's the extent of what I know. How could I fix that? Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-722029 Share on other sites More sharing options...
RhysAndrews Posted December 23, 2008 Author Share Posted December 23, 2008 Hmm, strange. The directories took a long while to create. Wonder if this will cause other issues? Thanks for your help! I think I'm done for now. -Rhys Quote Link to comment https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/#findComment-722053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.