Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/138103-help-with-directory-permissions/
Share on other sites

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

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)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.