Nicholas Johnson Nicholas Johnson - 4 months ago 9
HTML Question

PHP | Returns Invalid Links

So I have some PHP meant to read through a EVERYTHING in a directory (directories, sub directories, files, etc). This returns the proper list, but all of me links are 'invalid', but they're not. I can't click them or open them in a new window because it just goes to

about:blank
, but if I right-click then copy it, I can paste it and go to the valid webpage. I'm not too sure what would cause this. Here is my relevant code:
Example Output:



<html>

<head></head>

<body>
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/1.png">1.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/3.jpg">3.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/4.jpg">4.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/5.jpg">5.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/5x5_1.jpg">5x5_1.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/5x5_2.jpg">5x5_2.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/5x5_3.jpg">5x5_3.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/6.jpg">6.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/7.jpg">7.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/7a44d9dc51b3497ebe0f48be75c57e4d.png">7a44d9dc51b3497ebe0f48be75c57e4d.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/9.jpg">9.jpg</a>
</li>
<li class="title">Camera Roll
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/Camera Roll/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/IMG_00000001.jpg">IMG_00000001.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/IMG_00000002.jpg">IMG_00000002.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/IMG_00000003.jpg">IMG_00000003.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Image10.gif">Image10.gif</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Leedle.png">Leedle.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Music - Shortcut.lnk">Music - Shortcut.lnk</a>
</li>
<li class="title">Overwolf
<ol></ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/STANK FACE.png">STANK FACE.png</a>
</li>
<li class="title">Saved Pictures
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/Saved Pictures/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title">Screenshots
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/1.png">1.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/2.png">2.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/3.png">3.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/4.png">4.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/5.png">5.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (10).png">Screenshot (10).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (11).png">Screenshot (11).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (12).png">Screenshot (12).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (15).png">Screenshot (15).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (16).png">Screenshot (16).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (17).png">Screenshot (17).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (18).png">Screenshot (18).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (19).png">Screenshot (19).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (20).png">Screenshot (20).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (21).png">Screenshot (21).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (22).png">Screenshot (22).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (23).png">Screenshot (23).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (24).png">Screenshot (24).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (25).png">Screenshot (25).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (26).png">Screenshot (26).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (27).png">Screenshot (27).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (28).png">Screenshot (28).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (29).png">Screenshot (29).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (30).png">Screenshot (30).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (31).png">Screenshot (31).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (32).png">Screenshot (32).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (33).png">Screenshot (33).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (34).png">Screenshot (34).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (35).png">Screenshot (35).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (36).png">Screenshot (36).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (37).png">Screenshot (37).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (38).png">Screenshot (38).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (39).png">Screenshot (39).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (40).png">Screenshot (40).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (41).png">Screenshot (41).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (42).png">Screenshot (42).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (43).png">Screenshot (43).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (44).png">Screenshot (44).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (45).png">Screenshot (45).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (46).png">Screenshot (46).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (47).png">Screenshot (47).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (48).png">Screenshot (48).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (49).png">Screenshot (49).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (50).png">Screenshot (50).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (51).png">Screenshot (51).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (52).png">Screenshot (52).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (53).png">Screenshot (53).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (54).png">Screenshot (54).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (55).png">Screenshot (55).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (56).png">Screenshot (56).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (57).png">Screenshot (57).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (58).png">Screenshot (58).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (59).png">Screenshot (59).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (6).png">Screenshot (6).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (7).png">Screenshot (7).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (8).png">Screenshot (8).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshot (9).png">Screenshot (9).png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Screenshots.rar">Screenshots.rar</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/Thumbs.db">Thumbs.db</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Screenshots/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/Super_Smash_Bros_Melee_box_art.png">Super_Smash_Bros_Melee_box_art.png</a>
</li>
<li class="title">Uplay
<ol></ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/WTF RED SAYS HE LOOKS LIKE HOUSE.png">WTF RED SAYS HE LOOKS LIKE HOUSE.png</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/X-Ray_1.jpg">X-Ray_1.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/X-Ray_2.jpg">X-Ray_2.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/X-Ray_3.jpg">X-Ray_3.jpg</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/desktop.ini">desktop.ini</a>
</li>
<li class="title">iCloud Photos
<ol>
<li class="title">Downloads
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Downloads/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title">Shared
<ol>
<li class="title">Album
<ol></ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Shared/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title">Uploads
<ol>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/[clips4sale.com]2015.02.08_PSBT&amp;GH.mp4">[clips4sale.com]2015.02.08_PSBT&amp;GH.mp4</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/[clips4sale.com]2015.03.03_ILYBRD.mp4">[clips4sale.com]2015.03.03_ILYBRD.mp4</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/[clips4sale.com]2015.08.19_AnalRed_FULL.mp4">[clips4sale.com]2015.08.19_AnalRed_FULL.mp4</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/[clips4sale.com]2015.08.19_AnalWhite_FULL.mp4">[clips4sale.com]2015.08.19_AnalWhite_FULL.mp4</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/[clips4sale.com]2015.10.12_ReadyAimFire_WMV_3000Kbps_720p.mp4">[clips4sale.com]2015.10.12_ReadyAimFire_WMV_3000Kbps_720p.mp4</a>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/Uploads/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/iCloud Photos/desktop.ini">desktop.ini</a>
</li>
</ol>
</li>
<li class="title"><a href="C:\Users\Thatr\Pictures/kQRi9HT.png">kQRi9HT.png</a>
</li>
</ol>
</body>

</html>





PHP Code:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
function listFolderFiles($dir){
$ffs = scandir($dir);
echo '<ol>';
foreach($ffs as $ff){
if($ff != '.' && $ff != '..'){
echo '<li class="title">';
if(is_dir($dir.'/'.$ff)){
echo $ff;
listFolderFiles($dir.'/'.$ff);
}else{
echo '<a href="'.$dir.'/'.$ff.'">'.$ff.'</a>';
}
echo '</li>';
}
}
echo '</ol>';
}


listFolderFiles(getcwd());
?>

Answer

Problem : You seem to be missing the File Protocol (file:///) in all of your links.

Solution : Add proper protocol to the start of your URL's and you will be good to go as :

<a href="file:///C:/UsersThatr/Pictures/9.jpg">9.jpg</a>

Note : Use forward slash / for going deeper into directories in your links and also you shouldn't mix both slashes in links as because that's way it will also won't work then..!

Credit Goes To Ismail RBOUH For Pointing It Out First...!