views:

30

answers:

1

How would I go by Submiting a file that in the same directory as this script inside the $data. The below function is what I currently use. If you find any bugs in the current code please tell me as well :)

function post_data($site,$data){
    $datapost = curl_init();
 $headers = array("Expect:");
    curl_setopt($datapost, CURLOPT_URL, $site);
 curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
    curl_setopt($datapost, CURLOPT_HEADER, TRUE);
 curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($datapost, CURLOPT_POST, TRUE);
    curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
     curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
    ob_start();
    return curl_exec ($datapost);
    ob_end_clean();
    curl_close ($datapost);
    unset($datapost);    
}
A: 

Your first problem is that your relying on CURL, Just kidding, but here is one more way to skin this cat:

// prepare post headers $opts = array( 'http' => array( 'method' => 'POST', 'charset' => 'utf-8', 'timeout' => '60', // must be set for error handling 'content' => 'post data can be inserted here', // this can be a file )); $context = @stream_context_create($opts); // send post data and store response data $response = @file_get_contents('http://www.example.org/file.php', false, $context);

// using this posting method one does not have to rely on any external libraries

BugSquasher