Hello, I was working few days ago in somethig similar (file_get_contents function). I think I can check your script, debug it, and think about a solution right now.
I am a php developer with more than 5 years experience. Every day working with php, MySQL, html, css3, javascript, and linux systems.