Jump to content

Best way to download binary file


mtorbin

Recommended Posts

Hey all,

 

I am in the process of building a loop where each iteration will download (via http) a binary file (image or flv) from a source.  I could use wget but isn't there something built into php to handle this kind of thing?

 

Thanks,

 

- MT

Link to comment
Share on other sites

Thanks guys.  Tried doing this using curl and I'm getting odd results.  The files are downloading exactly as expected, however, each files returns a "false".  The only thing I can think of is that the curl does not actually return a boolean:

 

    if(exec("curl $remoteVideo -o $localVideo")) {
        writeEchoLog("Successfully downloaded " . $videoFileName . ".flv.");
    }
    else {
        writeEchoLog("There was an error downloading " . $videoFileName . ".flv.");
    }
    
    if(exec("curl $remoteImage -o $localImage")) {
        writeEchoLog("Successfully downloaded " . $imageFileName . ".jpg.");
    }
    else {
        writeEchoLog("There was an error downloading " . $imageFileName . ".jpg.\n");
    }

Link to comment
Share on other sites

Thanks!  This seems a lot more cryptic then just a straight shell command.  Maybe I'm missing something, but when I looked through the curl_setopt options, i couldn't find one for setting the location of the local file:

 

$file = "my_file.flv";

$curlInit = curl_init("http://myLocation.com/videos/");
$fileReader = fopen($file, "w");

curl_setopt($curlInit, CURLOPT_FILE, $fileReader);
curl_setopt($curlInit, CURLOPT_HEADER, 0);

curl_exec($curlInit);
curl_close($curlInit);
fclose($fileReader);

 

So, the curl session is based upon $curlInit . $file, right?

 

  - MT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.