468,505 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Can't get the d*mn script to work

I'm just learning PHP and I need some help with this script.

The purpose of this script is to hide the location of the file that's
to be downloaded.

The file (test.zip) is located here:
http://members.lycos.co.uk/username/directory2/test.zip and the script
(downlod.php) is located here:
http://members.lycos.co.uk/username/...1/download.php

The problem is that the script assumes the file to be downloaded is in
directory1 with the script. So the only thing that downloads is an
empty zip file.

How do I specify in the script where the test.zip file is located at?
I've been researching this thing for days and I can't find anything
that works.
<?php
$dir = "../username/directory2/";
$filename = "test.zip";
$file = $dir.$filename;

header ( "Content-type: application/zip" );
header ( "Content-Disposition: attachment; filename=test.zip" );
readfile ( 'test.zip' );
?>
Jul 17 '05 #1
4 1416
Mike wrote:
....
How do I specify in the script where the test.zip file is located at?
I've been researching this thing for days and I can't find anything
that works.
<?php
$dir = "../username/directory2/";
Perhaps you mean
$dir = '../directory2/';
$filename = "test.zip";
$file = $dir.$filename;
if (!is_readable($file)) die($file . ' is not readable.');
header ( "Content-type: application/zip" );
header ( "Content-Disposition: attachment; filename=test.zip" );
readfile ( 'test.zip' );
Maybe you want to readfile($file) instead
?>

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2
Nel
>
<?php
$dir = "../username/directory2/";
$filename = "test.zip";
$file = $dir.$filename;

header ( "Content-type: application/zip" );
header ( "Content-Disposition: attachment; filename=test.zip" );
readfile ( 'test.zip' );
?>


try fpassthru($file); instead of readfile

Nel
Jul 17 '05 #3
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message news:<40***********************@ptn-nntp-reader04.plus.net>...

<?php
$dir = "../username/directory2/";
$filename = "test.zip";
$file = $dir.$filename;

header ( "Content-type: application/zip" );
header ( "Content-Disposition: attachment; filename=test.zip" );
readfile ( 'test.zip' );
?>


try fpassthru($file); instead of readfile

Nel

It's still not working. If the realpath function was disabled, would
that cause this script not to work? I'm thinking that maybe that's the
problem.
Jul 17 '05 #4
Nel
"Mike" <li************@yahoo.com> wrote in message
news:3e**************************@posting.google.c om...
It's still not working. If the realpath function was disabled, would
that cause this script not to work? I'm thinking that maybe that's the
problem.


Mike,

Here is a script I used for downloading pdf files. Please feel free to
adapt it.
__________________________________
Call this file download.php
<?php

$fileid = array ( "SFK_petition" => "petition.pdf",
"SFK_poster" => "poster.pdf",
"SFK_letter01" => "letter01.pdf",
"SFK_letter02" => "letter02.pdf",
"SFK_event01" => "event01.pdf");
$filepath = "documents/";

if ($fileid[$file] != "") {

// We'll be outputting a PDF
header("Content-type: application/pdf");

// Define what it will be called
header("Content-Disposition: attachment; filename=SFK_".$fileid[$file]);

// The PDF source is in original.pdf
readfile($filepath.$fileid[$file]);
}
?>
____________________________________
Call the script with download.php?file=SFK_petition

or file equal to any of the included arrays. If the value of file is not
recognised, it returns a blank screen. You could add else {
header("Location: http://www.example.com"); } to redirect to another page.

The second part of the array is the filename. The file saves as
SFK_petition.pdf

Nel
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by godwin | last post: by
6 posts views Thread by scottyman | last post: by
4 posts views Thread by Sandeep Singh | last post: by
reply views Thread by =?Utf-8?B?U3RldmVv?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.