473,473 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1540
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: DKM | last post by:
I need an equivalent for the following: document.getElementById('equation').update(); from Mathplayer to use it in Mozilla based browser. When I change any text node, the page updates just...
1
by: godwin | last post by:
US- MN - Functional Oracle Consultants Salary: Your Best, Start Date: Immediate, Duration: April 4, 2005 - Jan 6, 2006 Number Of Openings: 4, Primary Skills: Oracle Consultants 1 -- with...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
4
by: Sandeep Singh | last post by:
I m building an application in which I redirect the user to a particular page. In the Page Load event of the that page , I assign a variable some value. Then I call the Button click event on that...
6
by: recherche | last post by:
Hi! Is the following program valid, although it compiles and executes successfully? // params modifier // used to declare array parameter // value type, no constructor using System;
0
by: =?Utf-8?B?U3RldmVv?= | last post by:
I have a mn-500 and I am trying to get in so that I can create a password so that my neighbors will stop using my connection. I thought that if I used 192.168.0.1 that I would be able to get in but...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.