SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php remote downloader..

    hey guys
    i was wondering if any one had any idea how i could make a php script that i can put a website file name in e.g. http://somewhere.com/file.exe and make it download onto that computer?

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    file_get_contents
    file_put_contents
    Those two functions would be the easiest way to do it, although if you need more advanced functionality then look at the other filesystem functions in the PHP manual.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    code ninja hamstu's Avatar
    Join Date
    Nov 2002
    Location
    Montréal, Canada
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use curl, or fopen too.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i can see the basics of that..but how would i make it get the file then download it onto my server

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you can see the basics of file_get_contents and file_put_contents, then nothing more needs to be said - all you need is the basics! file_get_contents gets the contents, file_put_contents puts the contents, all you have to do is specify where to get the contents from and where to put them.
    PHP questions? RTFM
    MySQL questions? RTFM

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    soo would something like this do it?

    <?php
    $file = file_get_contents ('http://somewhere.com/file.exe');

    file_put_contents ('mainfile.exe', '$file');
    ?>

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm i think ive done somethign wrong there... it creates the file but its only 5kb and its corrupt..

  8. #8
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, you have done something wrong. But no, check the file again - it's 5 bytes, not 5 kilobytes. In general, it's just bad practice to quote a variable unless it is part of a string (e.g., "$file" is bad, but "filename: $file" is not). However, you've made the common mistake of not realizing that PHP treats single quotes (') and double quotes (") differently - inside a string delineated by single quotes, PHP does not expand variables. If you open up your mainfile.exe in a text editor, you'll find the string "$file" in there, not the contents of $file that you want to be in there. Remove the quotes from around $file and you should be good to go.
    PHP questions? RTFM
    MySQL questions? RTFM

  9. #9
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    darn proxy server here still thinks its downloading here so it blocks it

  10. #10
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what im trying to do is because here at work we cant download anything, i thoguht if we made something like this then it would get the fiels to my webserver.. do you have any ideas?

  11. #11
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i think it did wotk i was just typing an address thats blocked here lolz
    thanks so much ill double check when i get home thta it worked

  12. #12
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Auckland, New Zealand
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it finanly worked here lol thank you so much


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
  •