xzolian Posted July 10, 2009 Share Posted July 10, 2009 I'm trying to use PHP and curl to save an image from a webcam server (http://dorgem.sourceforge.net/). If I just use the address of the server in Firefox the image displays fine. If I put the server address in a img tag in a plain html file it works: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <img src="http://someserver.com:8080" /> </body> </html> If I try to use PHP and curl to grab the image it just hangs unless I set CURLOPT_TIMEOUT. Regardless, it never returns the image. Here is the code I'm using: $url = "http://someserver.com:8080"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4); curl_setopt($ch, CURLOPT_TIMEOUT, ; $fileContents = curl_exec($ch); print_r(curl_getinfo($ch)); echo "\n\ncURL error number:" .curl_errno($ch); echo "\n\ncURL error:" . curl_error($ch); echo $fileContents; And the output: Array ( [url] => http://someserver.com:8080/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0.516388 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 ) cURL error number:28 cURL error:connect() timed out! Using the Firefox extension Life HTTP Headers I was able to see the headers: http://someserver.com:8080 GET / HTTP/1.1 Host: http://someserver.com:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729) Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.x 200 OK Server: Dorgem/2.1.0 Date: Fri, 10 Jul 2009 18:03:52 GMT Content-Type: image/jpeg Content-Length: 37214 Last-Modified: Fri, 10 Jul 2009 18:03:52 GMT Cache-Control: no-cache, private, must-revalidate Pragma: no-cache Expires: 0 Any suggestions on how I can use PHP to save this image to a directory on the server the script is running? Link to comment https://forums.phpfreaks.com/topic/165521-save-image-from-streaming-jpeg-server/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.