Loading array from file within a class (beginner)

Hi Experts!

I’m a sound engineer. I’m using an open source file repository - Sonuku dump - so clients can retrieve audio files from me. Despite being a newb with php, I’ve made some good small hacks, including email notification when a client downloads a file - very useful for me to know!.

I’m now trying to add a bit of back end to this script, so I can add private folders and users at easily. All going well so far but I’m totally stuck with trying to load an array from a file, within a class.

Originally, the array is declared as a constant at the top of the class:

[php]
var $CFG_PRIVATE = array(
“folder1/”,
“folder2/”
); //hides these folders unless logged in
[/php]

Later on, this array is used like thus:

[php]
foreach($this->CFG_PRIVATE as $private) {
if (preg_match("/^".preg_quote($private, ‘/’)."/i",$this->DIR."/") && !$this->checkpass($_SESSION[‘DUMP_PASS’])) {
$foundmatch = true;
}
[/php]

With another (separate) array for users, I successfully got it to load it’s data from a csv file with this code:

[php]
$dump->DUMP_PASS = array();
$arrLines = file(’/path/to/users.txt’);
foreach($arrLines as $line) {
$dump->DUMP_PASS = explode( ‘,’, $line);
}
[/php]

Can anybody advise me how I construct a function to load the array from a file, such that the array can be used as it is being used in code snippet #2 ?? I hope I have explained that clearly, any help would be massively appreciated.

thanks…
green_as

well, I sorted it out myself, took me for ever though, even though it is so basic!! :o

[php]
function readfolders() {
$handle = fopen("/path/to/folders.csv", “r”);
if( $handle ) {
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
return $data;
}
fclose($handle);
}
}
[/php]

Then I call it like this, and get the data into my array correctly

[php]
$this->CFG_PRIVATE=$this->readfolders();
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service