RE: Re: need help in reading folder

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I might approach this problem using the scandir() function.  The scandir ()
function reads the filenames of a given directory (including
subdirectories).  Using the scandir() function you can create a map of every
file on your drive.  I would create a function that can be called
recursively to scan all subdirectories below the root directory of the disk.
The first items in each directory will be "." And ".."  You will have to
ignore those files.  Use is_dir() to determine if a item scandir() returns
is a directory that needs to be scanned.

 

function mapdir($target_dir) {

                $x = scandir($target_dir);

                $c = count($x) + 1;

                for($i=2;$i<=$c;$i++) {

                                $td = $target_dir. '/'. $x[$i];

                                if(is_dir($x[$i]) {

                                                $sd = mapdir($td);

                                                while($t = each($sd)) {

                                                                $r[] = $t;

                                                }

                                } else {

                                                $r[] = $td. '/'. $x[$i];

                                }

                }

                return $r;

}

 

This is just an example.   If my logic is correct (I am  pretty tired at the
writing), this should produce a massive numerically indexed array with each
file's path stored as the value of each index, and without any directory
names being stored in the array.  By starting the value of $i at 2, I
skipped the values of dot (.) and double (..) that start each directory.

 

In your case, this function might be called with the line: $d =
mapdir("d:/");

 

>From this point, you can store the result to build links or do lookups
later.  You could serialize the result and store it in a flat file.  You can
store in a database.  Or you can generate links directly from the array by
making the value of each index the value of the href property of  anchor
tags.  If you want only MP3 files you can filter to make sure that only
files ending in ".mp3" get added to the $r.  I would use a regular
expression for this, but you could  use some of the string handling
functions built into php to do this as well.

 

I have used a similar process to map a directory where user files were
stored and the directory was always changing.  I used an object-oriented
solution wherein I replaced $r with $this->r with the result being a long
two dimensional array with the name of each file as the index (all "." In
the file name being replaced with something like "~x~"), and the values of
each being the path to that file.  This way I could convert say,
"myfile.txt" to "myfile~x~txt" and then use that to access the array
directly to get the path to a file.  This, of course, meant that each file
name had to be unique throughout all the directories and subdirectories.

 

I hope this helps you find your own solution to your problem.

 

 

gentlemike2

 

From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of Uzair
Sent: Thursday, June 03, 2010 4:33 AM
To: php-objects@xxxxxxxxxxxxxxx
Subject:  Re: need help in reading folder

 

  

Dear total media file size is 40 Tera bytes contain many media files.
It make no sense to copy all media files from d drive to c drive ???
i want to give link from d drive

here is code

Dear :
I just want to give referenc of my files of media in D: drive 

<?php echo "<A HREF=file:///E:/media/a.mp3 <file:///E:\media\a.mp3> >";
?><img src="images/download-icon2.jpg" border="0" width="25" height="25"
/><?php echo "</A><BR>\n"; ?>

this is code every one says file:///E:/media/a.mp3 <file:///E:\media\a.mp3> 
will work but its not working please help.

--- In php-objects@xxxxxxxxxxxxxxx <mailto:php-objects%40yahoogroups.com> ,
<gordon.leonard@...> wrote:
>
> 
> 
> another message that makes no sense....
> 
> You want to create a link to an mp3?
> 
> copy the file to your server using some ftp software, then in your html
create an "<a" tag:
> 
> download my mp3 <a href = "myfile.mp3">here</a>
> 
> 
> 
> 
> 
> ________________________________
> From: Uzair <uzair05csmehran@...>
> To: php-objects@xxxxxxxxxxxxxxx <mailto:php-objects%40yahoogroups.com> 
> Sent: Thursday, 3 June, 2010 9:24:21
> Subject:  need help in reading folder
> 
> 
> i want to give a href=d:a.mp3 
> but its not working kinldy provide the valid code 
> Thanks
> 
> 
> another message that makes no sense wh
> 
> [Non-text portions of this message have been removed]
>





[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux