使用PHP中的curl将文件上载到SalesForce中的Case

时间:2016-03-11 13:03:35

标签: php curl salesforce

if(isset($_POST['submit'])) {

   $url = "http://localhost/myuploader/upload.php"; // e.g. http://localhost/myuploader/upload.php // request URL
    $filename = $_FILES['file']['name'];
    $filedata = $_FILES['file']['tmp_name'];
    $filesize = $_FILES['file']['size'];

    if ($filedata != '')
    {
        $headers = array("Content-Type:multipart/form-data"); // cURL headers for file uploading
        $postfields = array("filedata" => "@$filedata", 
                            "Attchment1" => $filename,
                            "anrede" => trim($_POST['anrede']),
                            "Vorname" => trim($_POST['Vorname']),
                            "Betreff" => trim($_POST['Betreff']),
                            "Bemerkungen" => trim($_POST['Bemerkungen']),
                            "Email" => trim($_POST['Email']),
                            "Kündigungsfrist" => trim($_POST['Kündigungsfrist'])
                            );
        $ch = curl_init();
        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_HEADER => true,
            CURLOPT_POST => 1,
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_POSTFIELDS => $postfields,
            CURLOPT_INFILESIZE => $filesize,
            CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
            CURLOPT_SSL_VERIFYPEER =>false,
            CURLOPT_FOLLOWLOCATION => 1,
            CURLOPT_RETURNTRANSFER => true
        ); // cURL options
        curl_setopt_array($ch, $options);
        echo $result = curl_exec($ch);

        curl_close($ch);
    }
    else
    {
        $errmsg = "Please select the file";
    }

}

?>

<form action="application.php" method="POST" enctype="multipart/form-data">
<label for="radio">Anrede:</label>

<input type="radio" name="anrede" value="Herr" checked> Herr

<input type="radio" name="anrede" value="Frau"> Frau<br>

<label for="Name">Name</label><input  id="Name" maxlength="40" name="Name" size="20" type="text" /><br>

<label for="Vorname">Vor Name</label><input  id="Vorname" maxlength="80" name="Vorname" size="20" type="text" /><br>

<label for="Betreff">Betreff</label><input  id="Betreff" maxlength="80" name="Betreff" size="20" type="text" /><br>

<label for="Bemerkungen ">Bemerkungen</label><input  id="Bemerkungen" maxlength="40" name="Bemerkungen" size="20" type="text" /><br>

<label for="Email">Email</label><input  id="Email" maxlength="80" name="Email" size="20" type="email" /><br>

<label for="Kündigungsfrist">Kundigungsfrist</label><input  id="Kündigungsfrist" maxlength="40" name="Kündigungsfrist" size="20" type="text" /><br

<label for="upload">UPLOAD</label><input name="file" type="file" id="file"/><br>

<input type="submit" name="submit">

</form>

我收到错误

HTTP / 1.1 100继续HTTP / 1.1 415不支持的媒体类型日期:2016年3月14日星期一05:55:38 GMT Cache-Control:s-maxage = 0 Set-Cookie:BrowserId = rS0jnSB6SYuAI-trvn6i_g; Path = / ; Domain = .force.com; Expires = Fri,13-May-2016 05:55:39 GMT Expires:Thu,01 Jan 1970 1970 00:00:00 GMT Content-Type:application / json; charset = UTF-8 Transfer -Encoding:chunked [{“errorCode”:“UNSUPPORTED_MEDIA_TYPE”,“message”:“Apex REST不支持多部分/表单数据请求”}]

通过这个帮助我

0 个答案:

没有答案