SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Australia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Download a file from a remote server, then split the file

    G'day

    I've currently got no internet connection and need to download some linux cds (the LFS liveCD to be exact). So unable to download it all in one go, or install applications on a public computer I thought about hacking around with PHP again, download the file from the remove sever to my PHP server, split the file, then download it in bits from my server.

    I can't really think of a more elegant solution, and I haven't touched PHP in years, so this sounds like a fun PHP hack job. Any idea's where I should start ?

  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)
    I actually wrote a file-splitter in PHP a couple years back - needed to get around a 2MB limit on e-mail attachments. Anyway, this is how I would approach your problem:
    1) Open a file handle to the remote server. fopen
    2) Open a file handle to a local file.
    3) Read up to a megabyte at a time. fread
    4) Write the read bytes to the local file. fwrite
    5) When the local file reaches a certain size (whatever size you want your chunks to be), fclose that file and fopen another one.

    Remember that you'll likely also want to set_time_limit(0) and ignore_user_abort (the latter because I doubt you'll want to keep your browser open to your server the whole time, especially since your browser will likely assume the operation has timed out and terminate it). As you develop this, I'd recommend testing it on smaller files as you go so you don't discover after downloading the entire ISO that you screwed up royally. You'll also need to write something that will put the chunks back together on your local machine, but that should be trivial.
    PHP questions? RTFM
    MySQL questions? RTFM


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
  •