Solved

How to get http:// link files?

Posted on 2000-02-16
15
226 Views
Last Modified: 2008-03-06
I can use ftpget() in php3 get ftp:// link files and save it in my server.
But how get http:// link files?
0
Comment
Question by:bobe_ab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 

Expert Comment

by:npappas
ID: 2528904
Can you just use fopen?
     $file = fopen("http://www.php.net/", "r");

you can parse through the file with:
     while (!feof($file)) {
       ...
     }
and just save the lines to an open file handler.

Not the prettiest way of doing it, but it works. :)
0
 

Author Comment

by:bobe_ab
ID: 2529693
Thanks for you reply.
I am newer in php3.
Would you give me complet code?
Like:
My site is http://www.bobe.net under / I have Download dir, I want GetFile.php3, It can download http://mysql.org/files1.zip and save it in Download dir.

Thanks a lot!!
0
 

Author Comment

by:bobe_ab
ID: 2529694
Adjusted points to 150
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Expert Comment

by:maxkir
ID: 2530242
$file = fopen("http://www.php.net/", "r") or die ("unable to open remote file");
$file_local = fopen("/tmp/file","w") or die ("unable to open local file for writing");;
     while (!feof($file)) {
        fputs($file_local, fgets($file, 4096));
     }
fclose($file_local);
fclose($file);
0
 
LVL 2

Accepted Solution

by:
maxkir earned 150 total points
ID: 2530274
More exactly :

File GetFile.php3:
<?php
$file = fopen("http://mysql.org/file1.zip", "r") or die ("unable to open remote file");
$file_local = fopen("Download/file1.zip","w") or die ("unable to open local file for writing");;
     while (!feof($file)) {
        fputs($file_local, fgets($file, 4096));
     }
fclose($file_local);
fclose($file);
?>
0
 

Expert Comment

by:npappas
ID: 2530914
can't do much better then that!

curses maxkir... ya beat me to it.  ;)
0
 

Author Comment

by:bobe_ab
ID: 2533398
I test it,file can be download,but file1.zip can't be Extract.
Please tell me more!!!
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2534000
You mean you want to unzip this file after downloading ?
Then try to use external program like unzip via system() call:

system("cd Download; /usr/local/bin/unzip file1.zip");

Make sure that you have unzip program on your system.
0
 

Author Comment

by:bobe_ab
ID: 2534206
I download file1.zip in my local machine, use Winzip to Extact, but have error,I use BIN mode download it.
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2534261
Please check if size of file on FTP server is identical to downloaded file. If it is OK - I suggest that file is probably corrupted on FTP server.
0
 

Expert Comment

by:npappas
ID: 2534668
You might need to set up a binary transfer of the file.  How to do it with an fopen... I don't know, sorry.
0
 

Author Comment

by:bobe_ab
ID: 2534836
Thanks npappas!!
0
 

Author Comment

by:bobe_ab
ID: 2535216
My file is ok.
File size is 56k.
When I use GetFile.php3
The write file1.zip is 28k.
What's wrong with me?

Thanks for all reply.
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2535232
Try to replace thiese lines:

$file = fopen("http://mysql.org/file1.zip", "r") or die ("unable to open remote file");
$file_local = fopen("Download/file1.zip","w") or die ("unable to open local file for writing");

with this:
$file = fopen("http://mysql.org/file1.zip", "rb") or die ("unable to open remote file");
$file_local = fopen("Download/file1.zip","wb") or die ("unable to open local file for writing");

0
 

Author Comment

by:bobe_ab
ID: 2535815
It can't be work.
And I have a problem with it, When I close windows the file download stop?
Any good idea?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question