Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4463
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-02.dc1.easynews.com.POSTED!not-for-mail |
|---|---|
| From | Harry Putnam <reader@newsguy.com> |
| Newsgroups | comp.lang.php |
| Subject | Why and wherefore file downloads |
| Organization | Still searching... |
| User-Agent | Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux) |
| Message-ID | <87ehv25dm4.fsf@newsguy.com> (permalink) |
| Cancel-Lock | sha1:XhvGS3NtjBmle9VU7FmvseOPNYk= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 79 |
| X-Complaints-To | abuse@easynews.com |
| X-Complaints-Info | Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. |
| Date | Sat, 14 Jan 2012 13:43:31 -0500 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.php:4463 |
Show key headers only | View raw
I lifted something close to this off google, edited and now have it
working along with a cgi script of my own.
I'm way under skilled in this and I have noticed something remarkable
about the php part of the setup:
------- --------- ---=--- --------- --------
From_mohitsharma.net.php
php
<?php
// The file path where the file exists
$filepath = "**HERE**".$_GET['filename']."";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//setting content type of page
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filepath ));
header("Content-Description: File Transfer");
//Read File it will start downloading
@readfile($filepath);
?>
------- --------- ---=--- --------- --------
Notice the asterisked `**HERE**' in line 2.
It does not seem to matter what I put there, the script still works.
I started out carefully putting the exact path there but later noticed
that it worked no matter what I put there.
Can anyone tell me why that is so?
------- --------- ---=--- --------- --------
The cgi that calls the php code is short so included below as well.
------- --------- ---=--- --------- --------
cgi (note that the actual files for download are in `DocumentRoot/fr/':
------- 8< snip ---------- 8< snip ---------- 8<snip -------
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my ($frdir,$reg, @files, $php);
$php = './Frommohitsharma.net.php';
$reg = qr/\.(html|php|cgi|shtml|css|swf|sw[op]|~)$/;
$frdir = "../fr/";
print "content-type: text/html\n\n";
print "<html> <head>
<title>Free stuff </title>
</head>
<h3> Assorted downloads </h3>
<body bgcolor=\"beige\">
<ul>\n";
opendir my $dh, "$frdir" or die "Can't open $frdir: $!";
## exclude files matching $reg
@files = grep {!/$reg/ && -f "$frdir/$_"} readdir $dh;
for(sort @files){
my $sz = (stat ("$frdir/$_"))[7];
if($sz){
$sz = ($sz / 1024.00 /1024.00 );
}
printf "%s %.2f %s\n", "<li> <h5><h3><a href=\"$php?filename=$_\"><font size=\"1\" color=\"black\">sz:", $sz," mb - </font> $_</h3></a>\n";
}
print "</ul>
</body></html>\n";
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Why and wherefore file downloads Harry Putnam <reader@newsguy.com> - 2012-01-14 13:43 -0500
Re: Why and wherefore file downloads "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-15 00:06 +0100
Re: Why and wherefore file downloads Harry Putnam <reader@newsguy.com> - 2012-01-16 20:01 -0500
Re: Why and wherefore file downloads "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-18 09:21 +0100
csiph-web