/    Sign up×
Community /Pin to ProfileBookmark

script to download files in a certain directory…

can someone help me out here, i have an upload site, and want a download page, but all I have is a simple upload script to upload the files, but I want the page to download the files to list all the files in a certain directory so people can just click the link and download that file.

any help on this one???

thanks.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 29.2008 — why not just enable directory listings and point to the containting directory?

if not look to the [url=http://php.net/opendir]opendir[/url]() and [url=http://php.net/readdir]similar[/url] functions
Copy linkTweet thisAlerts:
@SyCoFeb 29.2008 — Do you want to download all the files in a directory as a single file? You'll need to execute a script on the server to create a zip on the fly. exec() can do that but how you create the zip depends on the server platform and the programs you have available on it.

If you just want to force a download of a file instead of having the browser or an application attempt to open it then this should do it.

[code=php]<?
//$file is the name of the file and its easiest to pass it to as a get var
//however it's not secure so I would also pass an MD5 hash to check

$file=$_GET['filename']

header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>[/code]
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — however it's not secure[/QUOTE]

Yeah, check paths and make sure its a valid file.
Copy linkTweet thisAlerts:
@steventowtauthorFeb 29.2008 — I got it from the first post.

thanks a lot.
×

Success!

Help @steventowt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...