I have two php files- 1st file (script.php) - <?php echo "<ul>"; function getFiles($path) { //Function takes a path, and returns a numerically indexed array of associative arrays containing file information, //sorted by the file name (case insensitive). If two files are identical when compared without case, they will sort //relative to each other in the order presented by readdir() $files = array(); $fileNames = array(); $i = 0; if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file == "." || $file == "..") continue; $fullpath = $path . "/" . $file; $fkey = strtolower($file); while (array_key_exists($fkey,$fileNames)) $fkey .= " "; $a = stat($fullpath); $files[$fkey]['size'] = $a['size']; if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-"; else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K"; else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb"; else $files[$fkey]['sizetext'] = $a['size'] . " bytes"; $files[$fkey]['name'] = $file; $files[$fkey]['type'] = filetype($fullpath); $fileNames[$i++] = $fkey; } closedir($dh); } else die ("Cannot open directory: $path"); } else die ("Path is not a directory: $path"); sort($fileNames,SORT_STRING); $sortedFiles = array(); $i = 0; foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f]; return $sortedFiles; } $files = getFiles("./../$Movie/"); foreach ($files as $file) print "<li><b><a href=\"http://www.turboupload.co.in/$Movie/$file[name]\">$file[name]</a></b></li>"; echo "</ul>"; ?> Code (markup): The file script.php is stored at 'http://www.turboupload.co.in/php/script.php' . Second File (main.php) - <?php $Movie = 'Apne'; include 'script.php'; ?> Code (markup): main.php is stored at 'http://www.turboupload.co.in/php/main.php' and 'http://www.turboupload.co.in/main.php' Now when I execute main.php from /php/ Directory (http://www.turboupload.co.in/php/main.php) it works fine. ie it bring the list of files from directory /Apne/ but when I execute main.php from home directory (http://www.turboupload.co.in/main.php) it dosen't work. script.php dosen't take the value of $Movie and displays content of home directory. Please help me out guys I am trying to solve it for last 5-6 Hours..
I tried "http://www.turboupload.co.in/$Movie" but I get error that http://www.turboupload.co.in/Apne is not a valid directory
That's because that is a URL, not a directory path If you are on a linux machine it will look like /home/yourusername/www/ or /home/yourusername/public_html/
Ok I changed it to $files = getFiles("/home/users/web/b84/ipw.amandeepmail/public_html/turboupload/$Movie/"); Code (markup): and the file main.php is in folder turboupload with contents <?php $Movie = 'Apne'; include 'http://www.turboupload.co.in/php/script.php'; ?> Code (markup): It is still not working
One thing I noticed that when I use 'script.php' in main.php include I get the desired results. When I use http://fullpath I don't get the results.
you CANNOT use a URL to include a php file. change the include in the main.php so it is include '/home/users/web/b84/ipw.amandeepmail/public_html/turboupload/php/script.php'; PHP:
It worked. Can you also tell me one more thing. I want to display only links to MP3 Files instead of all files in directory. Is this possible?