<?php $boundary="60d88283e4d1dedc8abd0999d51b6799"; $filename= basename($_FILES['fupload']['name']); $file=file_get_contents($_FILES['fupload']['tmp_name']); $request="--$boundary\r\nContent-Disposition:form-data; name=\"fupload\"; filename=\"$filename\"\r\nContent-Type:text/plain\r\n\r\n/$file\r\n--$boundary--\r\n"; $request1= nl2br($request); $ch2 = curl_init(); $length=strlen($request1); $headers3 = array( 'Accept-Encoding:identity', "Content-Type: Multipart/form-data; boundary=$boundary", "Content-Length: $length", 'x-wdox-version: 1.0', "x-wdox-ssid: $newstring" ); curl_setopt($ch2, CURLOPT_URL,"https://api.watchdox.com/document/".$guid->guid."/upload"); curl_setopt($ch2, CURLOPT_POST, 1); curl_setopt($ch2, CURLOPT_POSTFIELDS,$request1); curl_setopt($ch2, CURLOPT_HEADER, true); curl_setopt($ch2, CURLINFO_HEADER_OUT, true); curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers3); curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1); // allow redirects // receive server response ... curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); $server_output2 = curl_exec ($ch2); $code2 = curl_getinfo($ch2); var_dump($server_output2); ?>I want to upload file by using watchdox api.every thing is set at my end.but it says bad request 400 error.I think it might be some problem in my CURL code.Please help me out.I think problem is with post data.as php curl_setopt($ch2, CURLOPT_POSTFIELDS,$request1); take data either in array form or in htmlentity form.Please help me out or suggest any other way of defining boundary in php??
This is not how cURL and remote file upload works. Say the remote for has this file input box: <input type="text" name="file" /> Code (markup): then your cURL postdata should look like this: $postfields = array('filename' => '@' . realpath($_FILES['fupload']['tmp_name'])); PHP: