Well ofcourse it doesn't work, you have set the proxy for CURL. This has no effect on file_get_contents. Though, if you have curl, why don't you just use it? I don't think file_get_contents has proxy support.
Hmm, can you give me an example?, I dont like using curl when fetching contents. (i find it confusing)
Actually, you can in PHP 5.1.0+: $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar", 'proxy'=>"tcp://10.54.1.39:8000" ) ); $context = stream_context_create($opts); $file = file_get_contents('http://www.example.com/', false, $context); PHP:
Im trying to submit and retrieve a file form an external site. Im using file_get_contents , because Im unfamilar of how to do so with cURL. The external site has a form which you upload a file and it echos some content on the same page. This is the html source from the external site: <form enctype="multipart/form-data" method="post" > <p><input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> <input name="upload" type="file" /> <input type="submit" value="Show" /></p> </form> Code (markup): This is the bit where the content is echo'd after the upload: <div id="output"> the echo'd content from the uploaded file is contained within this tag on the external site </div> Code (markup): I managed to grab the form but it dont function, I click a file to upload, but I cant get the file to display on my site. Heres the code: <?php $url = "http://www.externalsite.com"; $rurl = file_get_contents($url); $i = 1; while($i <= 5) { $start = explode('<form enctype="multipart/form-data" method="post" >', $rurl); $end = explode('</form>', $start[$i]); $table .= $end[0]; $i++; } echo $table; ?> Code (markup):
yes, you dont need $i. I think, problem here $url="http://www.externalsite.com/index.html"; -> full link.
Thanks but I don't think you understand my question, I was suggested to use curl, i tried using curl and got stuck because curl requires you to define the form name or form action which the site does not have, so i tried it with file_get_contents, I managed to grab the form but its not echoing the output after i click the submit button, all my code does so far is embed the upload form. On the external site I'd upload a file and it would echo the ouput on the same page just below the form within the: <div id="output"></div> tags.
file_get_content only GETs the content not POSTs, use curl or file_post_contents that is a function that someone made that make using curl easier (found searching google).
if you post the contents and you want to get the <div> then you can run a RegEx (ereg,preg_match) .. but if you need to POST and after that to grab the echoed <div> (and the rest of the code) then you should use cURL
Just another note, every form must have an action page. If left empty, usually it is the same page as where the form is.