我正在使用AFNetworking将图像上传到服务器。一切似乎都很好。但是,当我检查图像文件夹时,图像是0字节。 empty cannot be displayed.
我的PHP代码。
<?php
header('Content-type: application/json');
include 'connection.php';
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
$username = $_POST['username']
$image = $_POST['image'];
$sql = "SELECT id FROM photos ORDER BY id ASC";
$res = mysqli_query($conn,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}
$path = "images/$id.jpg";
$actualpath = "http://www.example.com.au/ios/$path";
$sql = "INSERT INTO photos (image) VALUES ('$actualpath')";
if(mysqli_query($conn,$sql)){
file_put_contents($path,base64_decode($image));
$response["Result"] = "TRUE";
$response["message"] = "Successfully Uploaded";
}
}else{
$response["Result"] = "FALSE";
$response["message"] = "Nothing";
}
echo json_encode($response);
$conn->close();
?>
我正在使用以下Objective C代码。
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"username": _username.text,
};
[manager POST:@"http://example.com.au/ios/addUser.php" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imageData name:@"image"];
}
success:^(AFHTTPRequestOperation *operation, id responseObject) {}
运行代码后,我从服务器获得成功响应,但图像为空。