Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

all the filenames as links I can click on

Posted on 2013-11-05
3
Medium Priority
?
209 Views
Last Modified: 2013-11-07
Using php, I want to list all the filenames in a folder as hyperlinks


folder
<a href="file1.wmv" target="_blank">file1.wmv</a>
<a href="file2.wmv" target="_blank">file2.wmv</a>
<a href="file3.wmv" target="_blank">file3.wmv</a>
0
Comment
Question by:rgb192
3 Comments
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39624323
Something like this:

<?php 
$folder    = '.';
$files = scandir($folder);

foreach ($files as $file):
	printf("<p><a href='%s' target='_blank'>%s</p>",$file, $file);
endforeach;
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39624392
No points for this, but... You may want to filter the list of files a little bit, in case your process is not the owner.
0
 

Author Closing Comment

by:rgb192
ID: 39629570
This will work for displaying all the filenames

Thank you

A related question has filenames with spaces

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28287715.html
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question