Jump to content

Post to external site


newbtophp

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.