void readSource(
&$source,
$URL, [
$symbolic = null], [
$uncompression = 0], [
$directoryDepth = -1])
|
|
Create a reader to read the URL $URL.
If the URL is a directory, it will recursively read that directory. If $uncompressionLevel is not null, the archives (files with extension tar, zip, gz or tgz) will be considered as directories (up to a depth of $uncompressionLevel if $uncompressionLevel > 0). The reader will only read files with a directory depth of $directoryDepth. It reader will replace the given URL ($URL) with $symbolic in the public filenames The default symbolic name is the last filename in the URL (or '' for directories)
Examples: Considere the following file system
a.txt
b.tar (archive that contains the following files)
c.txt
d.tgz (archive that contains the following files)
e.txt
dir1/
f.txt
dir2/
g.txt
dir3/
h.tar (archive that contains the following files)
i.txt
read('.') will return a reader that gives access to following files (recursively read current dir):
a.txt
b.tar
dir2/g.txt
dir2/dir3/h.tar
read('.', 'myBaseDir') will return the following reader:
myBaseDir/a.txt
myBaseDir/b.tar
myBaseDir/dir2/g.txt
myBaseDir/dir2/dir3/h.tar
read('.', '', -1) will return the following reader (uncompress everything)
a.txt
b.tar/c.txt
b.tar/d.tgz/e.txt
b.tar/d.tgz/dir1/f.txt
dir2/g.txt
dir2/dir3/h.tar/i.txt
read('.', '', 1) will uncompress only one level (so d.tgz will not be uncompressed):
a.txt
b.tar/c.txt
b.tar/d.tgz
dir2/g.txt
dir2/dir3/h.tar/i.txt
read('.', '', 0, 0) will not recurse into subdirectories
a.txt
b.tar
read('.', '', 0, 1) will recurse only one level in subdirectories
a.txt
b.tar
dir2/g.txt
read('.', '', -1, 2) will uncompress everything and recurse in only 2 levels in subdirectories or archives
a.txt
b.tar/c.txt
b.tar/d.tgz/e.txt
dir2/g.txt
The recursion level is determined by the real path, not the symbolic one. So read('.', 'myBaseDir', -1, 2) will result to the same files:
myBaseDir/a.txt
myBaseDir/b.tar/c.txt
myBaseDir/b.tar/d.tgz/e.txt (accepted because the real depth is 2)
myBaseDir/dir2/g.txt
Use readSource to do the same thing, reading from a specified reader instead of reading from the system files
To read a single file, you can do read('a.txt', 'public_name.txt') If no public name is provided, the default one is the name of the file read('dir2/g.txt') contains the single file named 'g.txt' read('b.tar/c.txt') contains the single file named 'c.txt'
Note: This function uncompress files reading their extension The compressed files must have a tar, zip, gz or tgz extension Since it is impossible for some URLs to use is_dir or is_file, this function may not work with URLs containing folders which name ends with such an extension
Parameters: