There are a number of ways to do this.  Mine is something like this:

if (has_read_perm($user_id, $file_id)) {
        send_file_to_browser($file_id);
} else {
        // print error message();
}

...

function has_read_perm($user_id, $file_id) {
        // check db table
        // return true/false
}

function send_file_to_browser($file_id) {
        $file_location = get_file_location($file_id); // get full path of
this file_id
        $file_mime = get_file_mime($file_id); // I store this info in the db
        $fp = fopen("$file_location","r"); 
        $buff = fread($fp,8000000); 
        header("Content-Type: $file_mime_type\n");
        echo $buff; 
}

function get_file_location ($file_id) {
        // return full path to the file, including file_name
}

function get_file_mime_type($file_id) {
        // return the original file mime type, I have this stored into the
db when a file is uploaded
}

Because you are sending a header here, you can't print html before the
function send_file_to_browser() is called.

-Ben

-----Original Message-----
From: Andrew Coles [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 12:50 PM
To: [EMAIL PROTECTED]
Subject: [PHP] manipulating files with php


I am creating a CRM system using php for my final year university project.
I would like to enable the storing of files on the system.  However I want
to restrict access to these files according to privilege tables stored in
local mysql tables.  In order to prevent access to the files by simply
typing the url, they would be stored outside the web directory.

Is it possible to create a php page which will read a local file from
outside the web directory and pass the data straight to the http output, in
affect allowing checking of a users status before allowing access to the
file?

I would be grateful for any suggestions,

Thanks,

Andrew



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to