FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Why and wherefore file downloads
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Why and wherefore file downloads [message #176653] Sat, 14 January 2012 18:43 Go to previous message
Harry Putnam is currently offline  Harry Putnam
Messages: 2
Registered: January 2012
Karma:
Junior Member
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";
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: bind_param - vars not literals
Next Topic: phpmyadmin config problems
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 09:40:35 GMT 2024

Total time taken to generate the page: 0.04030 seconds