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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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"); } Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.