I have a PHP script that captures an image from an external URL, reads it and one on my server The directory saves in the script is located in a php file and includes:
Everything works great there ...
What I would like to do is to script this for many URLs. The URL will be written in a form textarea, separated by comas (or other).
A submit button will then tell the script that it is in the form of the couple with all the URL and that whatever name is saved by it, it is not important (random is correct).
I am still a newbie, and I am learning PHP
edit My code looks like this:
& lt ;? Php error_reporting (E_ALL); $ Image_urls = Explosion ('\ n', $ _POST ['urls']); Forex currency ($ image_urls $ as image_url) {$ ch = curl_init (); $ Timeout = 0; Curl_setopt ($ CH, CURLOPT_URL, $ image_url); Curl_setopt ($ CH, CURLOPT_CONNECTTIMEOUT, $ timeout); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ CH, CURLOPT_BINARYTRANSFER, 1); $ Image = curl_exec ($ ch); Curl_close ($ ch); $ F = fopen ('/ home1 / path / public_html / path / saved' '' rand (). Time (). ".jpg", 'w'); Filitt ($ f, $ picture); Fclose ($ f); }? & Gt; This only works for the first, and does not return any errors ... any thoughts?
Thank you for your great help!
You need to remove the URL from a text-field and then loop on it:
& lt ;? Php $ image_urls = Explosion ('\ n', $ _POST ['urls']); # Will create a list of URLs, if each line contains a URL # The original settings and the starters only need to run once. $ Sequencer = 1; $ Timeout = 0; Forex currency ($ image_urls $ as image_url) {$ ch = curl_init (); Curl_setopt ($ CH, CURLOPT_URL, $ image_url); Curl_setopt ($ CH, CURLOPT_CONNECTTIMEOUT, $ timeout); // Getting binary data; curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ CH, CURLOPT_BINARYTRANSFER, 1); $ Image = curl_exec ($ ch); Curl_close ($ ch); $ F = fopen ("/ home1 / path / public_html / path / saved / image_ $ sequencer.jpg", 'w'); Filitt ($ f, $ picture); Fclose ($ f); $ Serial ++; }? & Gt; Obviously, the information you input should be clean, valid, and repeated: not only to avoid Goatses, but to avoid entries that break your application (eg That white lines).
Comments
Post a Comment