.htaccess - Browsing Windows File System Virtually in XAMPP with PHP & htaccess -


i'm developing app enable browsing windows file system in web browser. conceived of solution allowing wife @ photos stored on external hard drive connected network computer running xampp, alleviating need install software. i've gone on allow viewing movies, browsing music, etc. using various techniques serve content. woohoo!

there no problems accessing file system using following in httpd.conf (apache config):

<directory "h:/"> require granted allow rewriteengine on rewriteoptions inherit </directory> alias /externaldrive "h:/" 

originally, creating folder parameter using query string in url:

index.php?q1=pictures 

then creating $path variable:

if (isset($_get['q1'])) { $q1=($_get['q1']); $path=$q1."/"; } 

then feeding $path variable scan_dir:

$scan_dir="h:/$path"; $files_or_folders = scandir($scan_dir);  

then iterating through results, changing $file_or_folder variable additional logic (not included) file link or folder link:

foreach($files_or_folders $key => $file_or_folder){ // if files // display pictures or other content <a href="<?= $file; ?>"><?= $file ?></a> // if folders // display link folder <a href="index.php<?= $query."=".$folder; ?>"><?= $folder ?></a> } 

it works well, query string getting pretty ugly when file or folder few levels deep, eg:

index.php?q1=level_a&q2=level_b&q3=level_c 

and code required parse file path worse:

if (isset($_get['q1']) && isset($_get['q2']) && !isset($_get['q3'])){ $q1=($_get['q1']); $q2=($_get['q2']);     $q3=($_get['q3']); $path=$q1."/".$q2."/".$q3; $query="?q1=$q1&q2=$q2&q3"; } 

instead of getting file path way, figured using .htaccess redirect requests more elegant. so, revised code "/level_a/level_b/level_c" redirected index.php , path info feed scan_dir() created way:

#get uri (everything after www root) $request = $_server['request_uri'];  #explode path '/'    $folders  = explode("/", $request);   ob_start(); #loop through results foreach ($folders $folder) { echo $folder; echo "/"; } #save ob results in variable $path = ob_get_clean(); 

so, folder links this:

<a href="<?= $path.$folder ?>">$folder/a> 

this works great, 2 levels deep. @ third level, first folder repeated. in other words, link such "level_a/level_b/level_c/" being sent browser "level_a/level_a/level_b/level_c/". i'm missing something, simple, can't find it.

thanks in advance willing take crack @ convoluted question.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -