Jump to content


Photo

Upload File to a Remote Server


  • Please log in to reply
4 replies to this topic

#1 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 22 September 2006 - 11:34 PM

Hello,
I would like to have a file upload form with an action="upload.php". In the upload.php, i would like CURL or fsockopen to upload the file to a remote server via another file upload form and get/parse the output of the response page. I am fairly proficient with CURL but can not find out how to perform this task. Any help would be greatly appreciated.
Thanks

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 September 2006 - 12:54 AM

have you checked out at the curl_setopt area on php.net or usphp.com?

http://usphp.com/man...curl-setopt.php

There's an example toward the bottom that looks like exactly what you're looking for:
<?php

$file = "file_to_upload.txt";
$submit_url = "http://www.url_to_upload_to.com/upload_page.php";

$formvars = array("cc"=>"us \n");
$formvars[variable_1] = "bla bla \n";
$formvars[variable_2] = "bla bla \n";
$formvars[variable_3] = "bla bla \n";
$formvars[variable_4] = "bla bla \n";
$formvars[upfile] = "@$file"; // "@" causes cURL to send as file and not string (I believe) 

   // init curl handle
   $ch = curl_init($submit_url);
   curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");  //initiates cookie file if needed
   curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");  // Uses cookies from previous session if exist
   curl_setopt($ch, CURLOPT_REFERER, "http://www.last_url_for_referer_logs.com");  //if server needs to think this post came from elsewhere
   curl_setopt($ch, CURLOPT_VERBOSE, 1);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars);

   // perform post
   echo $pnp_result_page = curl_exec($ch);
   curl_close ($ch);

?>


#3 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 23 September 2006 - 02:02 AM

Yes, I have actually run across this very script. Only problem i have with it is the $file variable and getting that to work. It doesn't seem to work when you give it the exact path (C:\Documents and....) but i am not very knowledgeable on what exactly the file form input is giving the php file. Thanks for the help

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 September 2006 - 02:07 AM

you can refer to it recently uploaded files using the files array.

$file= $_FILES[key($_FILES)]['tmp_name'];
should provide the temporary filename to the script and upload just fine.

#5 Doqrs

Doqrs
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 23 September 2006 - 02:46 AM

after much adjustment to suit the needs that i didn't list, i was able to get it to work. Thank you very much. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users