Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Listing Files in a Directory

Posted on 2007-04-11
6
Medium Priority
?
200 Views
Last Modified: 2008-02-01
I'm trying to set up part of my website so it's easier to share files. To be frank I have no clue where to search.
There are a few things I would like it to do if any one can help:
- List files in the directory so that I don't need to update the page (auto list )
- Not have the exact location but have them as lets say" file.php?filename=test.rar" (stops leaching)

Formatting would be the easy part (i think) because that could be done in a loop if I'm correct

Please if anyone could give be a shove or a kick in the right direction I would be great full.
0
Comment
Question by:peterallsop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Zack Soderquist
ID: 18892721
You may want to look at some of the built in PHP Directory Functions

scandir might be a good one http://us.php.net/manual/en/function.scandir.php

Here's a link to all the directory functions http://us.php.net/manual/en/ref.dir.php
0
 
LVL 8

Accepted Solution

by:
netmunky earned 2000 total points
ID: 18892725
http://www.php.net/dir
has documentation on most of the functions you need to get the list

for getting the file, you'll need
http://www.php.net/manual/en/function.finfo-file.php
http://www.php.net/manual/en/function.readfile.php

you'll needs some security checks in this (so you don't serve /etc/passwd), but the gist of it is something like:
<?php
$finfo = finfo_open();
header( "Content-type: ".finfo_file( $finfo, $_GET['filename'] ) );
readfile( $_GET['filename'] );
?>
0
 
LVL 8

Expert Comment

by:netmunky
ID: 18892737
if you don't have access to install the PECL finfo extension, check out the depricated http://www.php.net/manual/en/function.mime-content-type.php
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:Zack Soderquist
ID: 18892775
scandir only works with PHP5

Here is a PHP4 alternative

$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}
sort($files);
print_r($files);
0
 
LVL 7

Expert Comment

by:Zack Soderquist
ID: 18892806
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}

foreach($files as $value) {
    echo "file.php?filename=".$value."<br />";
}
0
 

Author Comment

by:peterallsop
ID: 18904446
I'm using PHP 5 just to let you know. Thanks for all the info.
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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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