How to get http:// link files?

I can use ftpget() in php3 get ftp:// link files and save it in my server.
But how get http:// link files?
bobe_abAsked:
Who is Participating?
 
maxkirConnect With a Mentor Commented:
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
 
npappasCommented:
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
 
bobe_abAuthor Commented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
bobe_abAuthor Commented:
Adjusted points to 150
0
 
maxkirCommented:
$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
 
npappasCommented:
can't do much better then that!

curses maxkir... ya beat me to it.  ;)
0
 
bobe_abAuthor Commented:
I test it,file can be download,but file1.zip can't be Extract.
Please tell me more!!!
0
 
maxkirCommented:
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
 
bobe_abAuthor Commented:
I download file1.zip in my local machine, use Winzip to Extact, but have error,I use BIN mode download it.
0
 
maxkirCommented:
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
 
npappasCommented:
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
 
bobe_abAuthor Commented:
Thanks npappas!!
0
 
bobe_abAuthor Commented:
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
 
maxkirCommented:
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
 
bobe_abAuthor Commented:
It can't be work.
And I have a problem with it, When I close windows the file download stop?
Any good idea?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.