【发布时间】:2015-06-23 22:15:44
【问题描述】:
需要帮助,我一直在寻找这个,但仍然不知道为什么仍然会出错
我正在使用 php n curl 将文件上传到 API
html表单
<form enctype="multipart/form-data" method="post" action="/function/stickerGroup/postStickerGroup.php" id="addStickerGroup" class="form-horizontal">
<div class="form-group has-feedback">
<label class="col-sm-2 control-label">Image</label>
<div class="col-sm-5">
<input type="file" class="form-control" name="image" placeholder="Choose Photo..">
</div>
</div>
<div class="form-group">
<label for="" class="col-sm-2"></label>
<div class="col-sm-3">
<input type="submit" name="" value="Add Sticker" class="btn btn-info btn-block">
</div>
</div>
</form>
postStickerGroup.php
$filename = $_FILES['image']['name'];
$filedata = $_FILES['image']['tmp_name'];
$filesize = $_FILES['image']['size'];
$url = test.net/api/sticker-group;
$token = getToken();
$headers = array("Content-Type:multipart/form-data",'Api-Key: '.$token);
$postfields = array("filedata" => '@'.$filedata, "filename" => $filename);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
它一直给我错误
Deprecated: curl_setopt_array(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in /home/mamypoko/public_html/function/network/base.php on line 118
HTTP/1.1 100 Continue HTTP/1.1 200 OK Server: nginx/1.4.6 (Ubuntu) Date: Fri, 17 Apr 2015 07:00:44 GMT Content-Type: application/json; charset=utf-8 Content-Length: 53 Connection: keep-alive {"code":400,"status":"Invalid or missing parameters"}
需要帮助通过表单数据上传文件的示例代码
【问题讨论】: