getting an error msg while using file_get_contents()
Question
I am getting an warning messsage like this
Warning: file_get_contents() [function.file-get-contents]: stream does not support seeking
this is the code
$f=file_get_contents('https://api.facebook.com/method/stream.publish?message='.$facebook_message1[0].'%20'.$facebook_message1[1].'%20'.$facebook_message1[2].'%20'.$facebook_message1[3].'%20'.$facebook_message1[4].'%20'.$facebook_message1[5].'%20'.$facebook_message1[6].'%20'.$facebook_message1[7].'%20'.$facebook_message1[8].'%20'.$facebook_message1[9].'%20'.$facebook_message1[10].'%20'.$facebook_message1[11].'%20'.$facebook_message1[12].'%20'.$facebook_message1[13].'%20'.$facebook_message1[14].'%20'.$facebook_message1[15].'%20'.$facebook_message1[16].'%20'.$facebook_message1[17].'%20'.$facebook_message1[18].'%20'.$facebook_message1[19].'%20'.$facebook_message1[20].'&attachment={"name":"'.$url.'","href":"'.$url.'","caption":"","description":"","media":[{"type":"image","src":"'.$facebook_image.'","href":"'.$cat.'"}]}&uid='.$user_id.'&access_token='.$access_token.'', NULL, NULL, 246);
$fID = substr_replace($f,"",-27);
Solution
Your immediate problem is that you are using the fourth parameter of file_get_contents
. You should simply omit that and cut off the relevant part of $f
with substr
later, like this:
$f = substr($f, 246);
However, there are many other issues:
- The handling of
$facebook_message
is atrocious. Save your sanity and useimplode('%20', $facebook_message)
instead of the manual string concatenation. - It's a really bad idea to use the magic numbers
246
and-27
in your code. How did you produce these values? Obviously they refer to a part of the result string delimited by something, so document that by writing code that finds the delimiters. Your current code will break the moment facebook does any small change to their return value format, even if that change is purely technical and makes no difference from a semantic point of view.
OTHER TIPS
You've told file_get_contents to seek to offset 246 with that final argument - you cannot do this with HTTP urls. You'll have fetch the entire response, then use
$f = substr($f, 246);
to extract the portions from 246 onwards.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow