SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Nice Mug jer's Avatar
    Join Date
    Apr 2000
    Location
    Canada
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    retrieving a remote file through http with PHP

    Hey, say I want to retrive the file http://www.politicswire.ca/index.htm from the domain www.politicsforums.com. I want to do this every 8 hours, how would I be able to do this using PHP (and cron jobs it seems).

    What's the easiest way to do this? It's just one file...
    Jeremy Watts :: Co-Founder
    Modevia Web Services :: Experience the Difference.

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a question that's kind of inline with this one as well. Would I be able to do something like jer wants to do with the include() function? Because I'm almost sure that include() is limited to the same server -- but I'm probably wrong....
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    include() will work across domains/servers.
    Kevin

  4. #4
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should check out the fsockopen and fopen functions - http://www.php.net/manual/en/function.fsockopen.php
    http://www.php.net/manual/en/function.fopen.php

    Reading about these two functions, esp. fsockopen helped me figure out how to upload an image that was on another server to my mine. It's probably the one you want to use.

    Phpbuiler has an article on using fsokopen with newsgroups - (Using sockets in php) http://www.phpbuilder.com/columns/armel20010427.php3

  5. #5
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by tubedogg
    include() will work across domains/servers.
    except if you're using windows as your platform... http://www.php.net/manual/en/features.remote-files.php

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it like this too:
    PHP Code:
    $output implode("",file("http://www.thesite.com/index.htm")); 
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, so to sum up all the suggestions from above, you should be able to (platform issues asside) be able to use HTTP or FTP protocol to access a remote file with the following functions:

    include()
    fopen()
    fread()
    file()

    Check out the manual entries for those functions.

  8. #8
    Nice Mug jer's Avatar
    Join Date
    Apr 2000
    Location
    Canada
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How could I save that file as a file on my own server? I'm guessing that's pretty easy
    Jeremy Watts :: Co-Founder
    Modevia Web Services :: Experience the Difference.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?
    $file = fopen("store.inc","w+");
    fputs($file, $youdata);
    fclose($file);
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •