Can't get the d*mn script to work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    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:


    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.z ip" );
    readfile ( 'test.zip' );
    ?>
  • Pedro Graca

    #2
    Re: Can't get the d*mn script to work

    Mike wrote:
    ....[color=blue]
    > 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/";[/color]

    Perhaps you mean
    $dir = '../directory2/';
    [color=blue]
    > $filename = "test.zip";
    > $file = $dir.$filename;[/color]

    if (!is_readable($ file)) die($file . ' is not readable.');
    [color=blue]
    > header ( "Content-type: application/zip" );
    > header ( "Content-Disposition: attachment; filename=test.z ip" );
    > readfile ( 'test.zip' );[/color]

    Maybe you want to readfile($file) instead
    [color=blue]
    > ?>[/color]


    --
    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. |

    Comment

    • Nel

      #3
      Re: Can't get the d*mn script to work

      >[color=blue]
      > <?php
      > $dir = "../username/directory2/";
      > $filename = "test.zip";
      > $file = $dir.$filename;
      >
      > header ( "Content-type: application/zip" );
      > header ( "Content-Disposition: attachment; filename=test.z ip" );
      > readfile ( 'test.zip' );
      > ?>[/color]

      try fpassthru($file ); instead of readfile

      Nel


      Comment

      • Mike

        #4
        Re: Can't get the d*mn script to work

        "Nel" <nelly@ne14.co. NOSPAMuk> wrote in message news:<40f7abb6$ 0$39736$ed2e19e 4@ptn-nntp-reader04.plus.n et>...[color=blue][color=green]
        > >
        > > <?php
        > > $dir = "../username/directory2/";
        > > $filename = "test.zip";
        > > $file = $dir.$filename;
        > >
        > > header ( "Content-type: application/zip" );
        > > header ( "Content-Disposition: attachment; filename=test.z ip" );
        > > readfile ( 'test.zip' );
        > > ?>[/color]
        >
        > try fpassthru($file ); instead of readfile
        >
        > Nel[/color]


        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.

        Comment

        • Nel

          #5
          Re: Can't get the d*mn script to work

          "Mike" <littleboyblu87 @yahoo.com> wrote in message
          news:3e7445e7.0 407162021.2db7c 2c1@posting.goo gle.com...[color=blue]
          > 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.[/color]

          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_petiti on" => "petition.p df",
          "SFK_poster " => "poster.pdf ",
          "SFK_letter 01" => "letter01.p df",
          "SFK_letter 02" => "letter02.p df",
          "SFK_event0 1" => "event01.pd f");
          $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($filep ath.$fileid[$file]);
          }
          ?>
          _______________ _______________ ______
          Call the script with download.php?fi le=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("Locatio n: http://www.example.com "); } to redirect to another page.

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

          Nel


          Comment

          Working...