mtorbin Posted March 17, 2008 Share Posted March 17, 2008 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 https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/ Share on other sites More sharing options...
cooldude832 Posted March 17, 2008 Share Posted March 17, 2008 you can mod headers to push data like a download Link to comment https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494063 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 You can use fopen to read a binary file. Link to comment https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494071 Share on other sites More sharing options...
mtorbin Posted March 17, 2008 Author Share Posted March 17, 2008 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 https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494120 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 Shell commands return 0 on success, equivelent to php's false. Any reason your not using the curl extension? Link to comment https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494121 Share on other sites More sharing options...
mtorbin Posted March 17, 2008 Author Share Posted March 17, 2008 Any reason your not using the curl extension? I am rather new to php so I only start using something once it's suggested I do so, like now. So what is this extension and how can I use it? - MT Link to comment https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494128 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 So what is this extension and how can I use it? Its all covered in the link I supplied. Link to comment https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494130 Share on other sites More sharing options...
mtorbin Posted March 17, 2008 Author Share Posted March 17, 2008 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 https://forums.phpfreaks.com/topic/96545-best-way-to-download-binary-file/#findComment-494141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.