newbtophp Posted August 31, 2009 Share Posted August 31, 2009 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> 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> 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; ?> Link to comment https://forums.phpfreaks.com/topic/172523-post-to-external-site/ Share on other sites More sharing options...
RussellReal Posted August 31, 2009 Share Posted August 31, 2009 I just tried to write up a script to do this and ran into two possible road blocks, CURL_PUT doesn't allow you to send a form field name to go along with the file pointer, unless I'm mistaken, and I did some googling and cURL's @filename doesn't exactly work thru php. hope sum1 else can give you a better answer. Link to comment https://forums.phpfreaks.com/topic/172523-post-to-external-site/#findComment-909596 Share on other sites More sharing options...
newbtophp Posted September 1, 2009 Author Share Posted September 1, 2009 I tried: <?php // Using CURL //URL $url = 'http://www.showmycode.com'; //External site /* Post Data */ $postData['upload'] = 'upload'; $postData['submit'] = 'submit'; $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL,$url); // set url to post to curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 50); // times out after 50s curl_setopt($ch, CURLOPT_POST, 1); // set POST method curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // add POST fields $buffer = curl_exec($ch); // run the whole process curl_close($ch); echo $buffer; ?> But still no luck, the site where the form is located is: www.showmycode.com On that site the form has no action or no name, so I find it hard to do it with curl, because on that site the output after the upload is echo'd back on the same page. Can you take a look at that site?, and let me know please. Thanks Link to comment https://forums.phpfreaks.com/topic/172523-post-to-external-site/#findComment-910133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.