RE: [PHP] manipulating files with php

From: Date: Wed, 09 May 2001 20:07:27 +0000
Subject: RE: [PHP] manipulating files with php
Groups: php.general 
Request: Send a blank email to php-general+get-52173@lists.php.net to get a copy of this message
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:ac398@dialstart.net] Sent: Wednesday, May 09, 2001 12:50 PM To: php-general@lists.php.net 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#52173) next »