我正在尝试通过curl发送文件,同时点击API来发布数据,将其发布到服务器中但没有文件内容。只有文件名正在服务器中更新而没有文件内容,上传后显示无效的CVS文件错误。我在postfiled中传递文件名,但是如何发送包含文件数据/内容的完整文件。
我需要将文件与文件内容一起上传,我正在(zend2)中执行此操作。下面是我从邮递员那里获取的php php代码,听说它的工作正常,但是如果同一件事(如果在php中应用)(zend2),则听到了不起作用,显示无效的CVS文件错误。
$file_details = $params['upload'];
foreach ($file_details as $key => $value) {
$filename = $file_details[0]['name'];
//curl start
$url = $this->EndPoint . 'uploaddata?&fileType=text';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
// CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"resFile\"; filename=\"$filename\"\r\nContent-Type: text/csv\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
"x-jwt-token: $token"
),
));
$response = curl_exec($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);
curl_close($curl);
}
<div class="row">
<div class="col-md-7 mb-3">
<div class="form-group">
<label for="FormControltest" class="heading-label">File Location</label>
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFile" name ="upload[]" multiple required>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
</div>
<div class="col-md-2 pl-0">
<!-- <a href="product_listing.html" class="text-white">-->
<button class="btn second-btn custom-margin btn-md" name ="submit" id ="submit" type="submit">Upload Files</button>
</a>
</div>
<div class="col-md-12 text-right mb-4">
<button type="button" class="btn pri-btn">Upload Listing</button>
</a>
</div>
</div>