download file

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

    download file

    How do I download files from the internet server to my computer?

    How do I tell the script the correct hard drive folder on my computer to
    copy the files to?

    After connecting to the internet server, I am trying:

    $_SESSION['archive_dir_re ad'] = "/uploaddir/"; // directory on server
    $_SESSION['archive_dir_st ore'] = "c:/_picture_file/"; // directory on
    computer

    copy($_SESSION['archive_dir_re ad'].$_SESSION['picture1'],
    $_SESSION['archive_dir_st ore'].$_SESSION['picture1'])

    $_SESSION['picture1'] is the file name

    How do I address my computer from the internet?

    ftp://c:/_picture_file/

    or http://c:/_picture_file/

    http://ip address/c:/_picture_file/

    Thanks for the help.

    Ken


  • Alvaro G Vicario

    #2
    Re: download file

    *** Ken wrote/escribió (Wed, 18 Aug 2004 08:11:16 GMT):[color=blue]
    > How do I address my computer from the internet?[/color]

    Luckily, that's impossible! Let your web browser download it. Point browser
    to http://domain.com/folder/file.extension and then use the "Save as"
    option.


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Questions sent to my mailbox will be billed ;-)
    --

    Comment

    • Ken

      #3
      Re: download file

      > > How do I address my computer from the internet?
      I can see why that is not done!!

      Can I place the download script on my computer and pull the files down to my
      hard drive?

      Rather than push them down from the internet server.

      I have a number of files; the number will vary and is controlled by the
      webpage I am writing. The viewer uploads the files to a server directory.
      I need to find an PHP script to transfer the files to my computer. I would
      like PHP to automatically download the proper file.

      There must be way of taking the files off the internet server and moving
      them to my hard drive.

      How do I do that?
      Can I configure the copy command to do that?

      Thanks for the help.

      Ken

      $_SESSION['archive_dir_re ad'] = "/uploaddir/"; // directory on
      server
      $_SESSION['archive_dir_st ore'] = "c:/_picture_file/"; // directory on
      computer

      copy($_SESSION['archive_dir_re ad'].$_SESSION['picture1'],
      $_SESSION['archive_dir_st ore'].$_SESSION['picture1'])

      $_SESSION['picture1'] is the file name


      "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
      message news:1hgnm9frov wtu.9vaskpc72bn 8.dlg@40tude.ne t...[color=blue]
      > *** Ken wrote/escribió (Wed, 18 Aug 2004 08:11:16 GMT):[color=green]
      > > How do I address my computer from the internet?[/color]
      >
      > Luckily, that's impossible! Let your web browser download it. Point[/color]
      browser[color=blue]
      > to http://domain.com/folder/file.extension and then use the "Save as"
      > option.
      >
      >
      > --
      > -- Álvaro G. Vicario - Burgos, Spain
      > -- Questions sent to my mailbox will be billed ;-)
      > --[/color]


      Comment

      • Alvaro G Vicario

        #4
        Re: download file

        *** Ken wrote/escribió (Wed, 18 Aug 2004 09:16:46 GMT):[color=blue]
        > Can I place the download script on my computer and pull the files down to my
        > hard drive?[/color]

        Sure, but of course you need the adequate environment (a web server
        accesible from outside and a PHP interpreter). It's probably easier to just
        use a download tool like GetRight or wget and program the download. Some of
        them (esp. wget) are very flexible.


        --
        -- Álvaro G. Vicario - Burgos, Spain
        -- Questions sent to my mailbox will be billed ;-)
        --

        Comment

        • Ken

          #5
          Re: download file

          I have apache server on my computer also php.

          Do I have to change the configuration on the server to access the outside?
          I use the server to develop the php and MySql scripts.

          Can you suggest a script a script?

          I really appreciate the help!

          Ken

          "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
          message news:aaly4g9r28 bm$.munpc8e6xqw z.dlg@40tude.ne t...[color=blue]
          > *** Ken wrote/escribió (Wed, 18 Aug 2004 09:16:46 GMT):[color=green]
          > > Can I place the download script on my computer and pull the files down[/color][/color]
          to my[color=blue][color=green]
          > > hard drive?[/color]
          >
          > Sure, but of course you need the adequate environment (a web server
          > accesible from outside and a PHP interpreter). It's probably easier to[/color]
          just[color=blue]
          > use a download tool like GetRight or wget and program the download. Some[/color]
          of[color=blue]
          > them (esp. wget) are very flexible.
          >
          >
          > --
          > -- Álvaro G. Vicario - Burgos, Spain
          > -- Questions sent to my mailbox will be billed ;-)
          > --[/color]


          Comment

          • Alvaro G Vicario

            #6
            Re: download file

            *** Ken wrote/escribió (Wed, 18 Aug 2004 16:58:31 GMT):[color=blue]
            > Do I have to change the configuration on the server to access the outside?
            > I use the server to develop the php and MySql scripts.[/color]

            It really depends on many factors: Apache config, firewalls, routers...
            Apache must be listening your PC's external IP (not only 127.0.0.1),
            firewall must allow external access to port 80 and routers must have NAT
            configured to send traffic to your computer.

            --
            -- Álvaro G. Vicario - Burgos, Spain
            -- Questions sent to my mailbox will be billed ;-)
            --

            Comment

            • Ken

              #7
              Re: download file

              "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
              message news:14umxukqqr h7d.18qmy4yqec2 aj.dlg@40tude.n et...[color=blue]
              > *** Ken wrote/escribió (Wed, 18 Aug 2004 16:58:31 GMT):[color=green]
              > > Do I have to change the configuration on the server to access the[/color][/color]
              outside?[color=blue][color=green]
              > > I use the server to develop the php and MySql scripts.[/color]
              >
              > It really depends on many factors: Apache config, firewalls, routers...
              > Apache must be listening your PC's external IP (not only 127.0.0.1),
              > firewall must allow external access to port 80 and routers must have NAT
              > configured to send traffic to your computer.
              >
              > --
              > -- Álvaro G. Vicario - Burgos, Spain
              > -- Questions sent to my mailbox will be billed ;-)
              > --[/color]

              I set up PHP as follows: But the file save dialog box does not open in
              Internet Explorer version 6.0.2800.1106.

              $type = image/pjpeg
              $size = 3548
              $pict = the-picture-name.jpg

              header("Content-type: application/$type");
              header("Content-disposition: attachment; filename=$pict" );
              header("Content-length: $length");
              readfile('$pict ');

              What am I doing wrong?

              Thanks!

              Ken


              Comment

              • Ken

                #8
                Re: download file

                $file = directory/WI-1117-01.gif
                header( "Content-Description: File Transfer" );
                header("Expires : 0");
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

                //header( "Content-Type: application/force-download" );
                header( "Content-Type: image/gif" );
                header( "Content-Disposition: attachment; filename=test.g if" );
                header( "Content-length: ".filesize($fil e));
                header( "Content-Transfer-Encoding: binary" );

                $testt = readfile($file) ;
                echo "<br><br>te stt = ".$testt;

                echo "<br><br>Comple ted";

                -------------------------------------------------------
                I have made some changes.

                I can now display the ASCII code for the image on my screen. The image is
                the visa.gif

                WI-1117-01.gif , image/gif , 518
                GIF89a8$Ä33f3f3 ff3fTffTfTTTTT3 fTTÌTÌÌÌÌÌÌÌÿÌÿ ÿÿTÿT3ÿTfÿÌfÿÌT ÿÿÌÿÿÿ,8$@ÿ
                "ZdizhªSµ¾pܲm mâB9¥^Ê,T`Ø( @AZGtJ=2OÕ ¬æèz¿à°xLÏç~ z=:OC¡`°%æ:ù¡ ¦
                ( X-wr:URSC#X "u 7"OI'?S\eoz^nZ ¢£¤54l¨j¡¥¬­[hU=²"- < ²
                5-Y?P½<?µT8"Ë--:MfPÆG 5CBÞE , ÞÁT>Yùú
                ..°ûÿùV¹HJÁfs `¥Z¸"Ã?'BoxJ! Å?jOËJsý × Á¹' <©;ç$ÈuuoB ²' "
                ù",<-ìs<'TÚ,.Z@Ûfd ~´?Ø5hB
                Ñ*QGÄ\ÔÓ?,I£ X°@ÖÓ"Y¸°?¤?¬? ?.·Á?]#oqÔrO89öø3` `
                æÄ"ê÷Þ̍ûµHTS¨ Ê~Å\Î̹KÆÈ/S&;

                testt = 518 // this is the result of readfile statement. The file size.
                So I am now in contact with the correct file, file size, and have downloaded
                the file as ASCII to the screen but did not saved it as a file (test.gif) on
                my hard drive.

                Completed
                -------------------------------------------------

                I read there is a problem with IE 6.0 I could not find a fix for it.

                Do you know the file name or number for the fix? Q??? K???
                Is the above script correct for readfile() and the headers?

                Ken


                Comment

                • Alvaro G Vicario

                  #9
                  Re: download file

                  *** Ken wrote/escribió (Mon, 23 Aug 2004 21:44:19 -0500):[color=blue]
                  > readfile('$pict ');[/color]

                  That way you're reading a file called $pict. Variables are not parsed
                  within single quotes. Try:

                  readfile($pict) ;


                  --
                  -- Álvaro G. Vicario - Burgos, Spain
                  -- Questions sent to my mailbox will be billed ;-)
                  --

                  Comment

                  • Alvaro G Vicario

                    #10
                    Re: download file

                    *** Ken wrote/escribió (Tue, 24 Aug 2004 01:37:28 -0500):[color=blue]
                    > $testt = readfile($file) ;
                    > echo "<br><br>te stt = ".$testt;
                    >
                    > echo "<br><br>Comple ted";[/color]

                    The echo's are fine for debugging but, of course, if you use them in the
                    final script your file will be messed.

                    --
                    -- Álvaro G. Vicario - Burgos, Spain
                    -- Questions sent to my mailbox will be billed ;-)
                    --

                    Comment

                    • Ken

                      #11
                      Re: download file

                      header( "Content-Disposition: attachment;
                      filename=".$_SE SSION['pictures'.$i]);
                      header( "Content-Type:".$_SESSIO N['pictures'.$i.' _type']);
                      header( "Content-length: ".$_SESSION['pictures'.$i.' _size']);
                      header( "Content-Transfer-Encoding: binary" );
                      readfile($_SESS ION['archive_dir_re ad'].$_SESSION['pictures'.$i]);

                      I finally was able to save a file from the internet server to my hard drive
                      thanks to all the help I received from the newsgroup.

                      For the next person to ask the question about downloading files, a few
                      pointers.
                      We know this but do not remember it.

                      The headers must be before any writing to the display, including html and
                      echo.
                      So basically, add a separate page for the headers.

                      I do have four other questions.
                      1. How do I define the hard drive directory for the files in the headers?
                      I added it to the filename, then the file name became the page name,
                      i.e., file.gif became download.gif download.php is the page file name.
                      header( "Content-Disposition: attachment;
                      filename=c:/temp/".$_SESSION['pictures'.$i]); The manual says the directory
                      name cannot be specified. Is that still true? Any work arounds?

                      2. Can I download multiple files at one time? Can you suggest a script for
                      handling multiple files?

                      3. Is there a way to download the files without going through the file
                      download box? Open the page and the files download to the specified
                      directory.

                      4. Do I need any other headers?

                      Thanks!!

                      Ken


                      Comment

                      • Alvaro G Vicario

                        #12
                        Re: download file

                        *** Ken wrote/escribió (Wed, 25 Aug 2004 04:49:18 -0500):[color=blue]
                        > 1. How do I define the hard drive directory for the files in the headers?[/color]

                        I'm pretty sure you cannot. Maybe that's a good idea: if you aren't careful
                        when browsing the web a malicious site could overwrite any important file
                        in your hard drive. Just think of all the times you've got a dialog when
                        about to type "enter" in your text editor ;-)
                        [color=blue]
                        > 2. Can I download multiple files at one time? Can you suggest a script for
                        > handling multiple files?[/color]

                        Short answer: no. HTTP connections are not persistent. Once the file is
                        served, the connection is closed. Even if the connection is keep-alive
                        type, I guess you need a browser request to serve another fiel. (Not sure
                        about pipelining though).

                        Workaround: use JavaScript to open pop-up windows and make it work through
                        usual pop-up blockers--i.e., make the window.open get tryggered by an user
                        event.
                        [color=blue]
                        > 3. Is there a way to download the files without going through the file
                        > download box? Open the page and the files download to the specified
                        > directory.[/color]

                        See first point. There *are* ways, but you probably need to write an
                        ActiveX control or signed Java applet.
                        [color=blue]
                        > 4. Do I need any other headers?[/color]

                        I don't think so.

                        --
                        -- Álvaro G. Vicario - Burgos, Spain
                        -- Questions sent to my mailbox will be billed ;-)
                        --

                        Comment

                        • Ken

                          #13
                          Re: download file

                          Thanks for the help.

                          Ken

                          "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
                          message news:17s14oygid 371.18pfkp7dhv3 ac.dlg@40tude.n et...[color=blue]
                          > *** Ken wrote/escribió (Wed, 25 Aug 2004 04:49:18 -0500):[color=green]
                          > > 1. How do I define the hard drive directory for the files in the[/color][/color]
                          headers?[color=blue]
                          >
                          > I'm pretty sure you cannot. Maybe that's a good idea: if you aren't[/color]
                          careful[color=blue]
                          > when browsing the web a malicious site could overwrite any important file
                          > in your hard drive. Just think of all the times you've got a dialog when
                          > about to type "enter" in your text editor ;-)
                          >[color=green]
                          > > 2. Can I download multiple files at one time? Can you suggest a script[/color][/color]
                          for[color=blue][color=green]
                          > > handling multiple files?[/color]
                          >
                          > Short answer: no. HTTP connections are not persistent. Once the file is
                          > served, the connection is closed. Even if the connection is keep-alive
                          > type, I guess you need a browser request to serve another fiel. (Not sure
                          > about pipelining though).
                          >
                          > Workaround: use JavaScript to open pop-up windows and make it work through
                          > usual pop-up blockers--i.e., make the window.open get tryggered by an[/color]
                          user[color=blue]
                          > event.
                          >[color=green]
                          > > 3. Is there a way to download the files without going through the file
                          > > download box? Open the page and the files download to the specified
                          > > directory.[/color]
                          >
                          > See first point. There *are* ways, but you probably need to write an
                          > ActiveX control or signed Java applet.
                          >[color=green]
                          > > 4. Do I need any other headers?[/color]
                          >
                          > I don't think so.
                          >
                          > --
                          > -- Álvaro G. Vicario - Burgos, Spain
                          > -- Questions sent to my mailbox will be billed ;-)
                          > --[/color]


                          Comment

                          • Aki Häkkilä

                            #14
                            Re: download file

                            Alvaro G Vicario wrote:[color=blue]
                            > *** Ken wrote/escribió (Wed, 25 Aug 2004 04:49:18 -0500):[color=green]
                            >> 2. Can I download multiple files at one time? Can you suggest a
                            >> script for handling multiple files?[/color]
                            >
                            > Short answer: no. HTTP connections are not persistent. Once the file
                            > is served, the connection is closed. Even if the connection is
                            > keep-alive type, I guess you need a browser request to serve another
                            > fiel. (Not sure about pipelining though).
                            >
                            > Workaround: use JavaScript to open pop-up windows and make it work
                            > through usual pop-up blockers--i.e., make the window.open get
                            > tryggered by an user event.[/color]

                            IE sucks in this aspect. If you expect that the users would use Mozilla
                            or some other browser that can handle MIME multipart content, it should
                            work with the following script:
                            - - - - - - - - -
                            <?
                            define(BOUNDARY , "thisisthebound ary");
                            header("Content-type: multipart/mixed; boundary=\"". BOUNDARY ."\"");
                            header("MIME-version: 1.0");

                            $file1="pic1.jp g";
                            $file2="pic2.jp g";

                            $fh = fopen($file1, "r");
                            $content1 = fread($fh, filesize($file1 ));
                            fclose($fh);

                            $fh = fopen($file2, "r");
                            $content2 = fread($fh, filesize($file2 ));
                            fclose($fh);

                            echo "--". BOUNDARY ."\r\n";
                            echo "Content-type: image/jpeg\r\n";
                            echo "Content-description: pic1.jpg\r\n";
                            echo "Content-disposition: attachment; filename=\"pic1 .jpg\"\r\n\r\n" ;
                            echo $content1;

                            echo "\r\n\r\n--". BOUNDARY ."\r\n";
                            echo "Content-type: image/jpeg\r\n";
                            echo "Content-description: pic2.jpg\r\n";
                            echo "Content-disposition: attachment; filename=\"pic2 .jpg\"\r\n\r\n" ;
                            echo $content2;

                            echo "\r\n\r\n--". BOUNDARY ."\r\n";
                            echo "Content-type: text/html\r\n\r\n";

                            echo "<html>
                            <head>
                            <title>dl finished</title>
                            <body>
                            <h2>Finished downloading</h2>
                            </body>
                            </html>\r\n";
                            echo "\r\n--". BOUNDARY ."--\r\n";
                            ?>
                            - - - - - - - - -

                            At least it worked when I tested with Mozilla Firefox, but I couldn't
                            figure out how IE would handle the multiparts properly.

                            - Aki

                            Comment

                            Working...