ConvertAPI / PHP代码上传/下载0字节

时间:2015-09-17 00:41:34

标签: php convertapi

我尝试使用PHP / CURL调用ConvertAPI RESTful API将表单上传PDF转换为PNG。当文件显示在服务器上时,文件上载正在运行,但是curl_getinfo没有返回任何内容,显示[size_upload] => 0和[size_download] =>有人可以在我的代码中指出错误吗?

define("UPLOAD_DIR", "./tmp/");
$rest_url="https://do.convertapi.com/Pdf2Image";

$up_file=UPLOAD_DIR.rand(100,999)."_".basename($_FILES['fileField']['name']);
if (!move_uploaded_file($_FILES['fileField']['tmp_name'], $up_file)) {
    die("Possible file upload attack!");
}

$cfile=new CURLFile($up_file);

$params=array(
    "ApiKey" => 11111111,
    "OutputFormat" => "png",
    "OutputFileName" => "converted.png",
    "File" => $cfile
    );

$ch=curl_init($rest_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$res=curl_exec($ch);
$headers=curl_getinfo($ch);
curl_close($ch);

echo "<pre>";
print_r($headers);
var_dump($res);

1 个答案:

答案 0 :(得分:0)

如果网址使用 https:// 编写,则上传stops。它应该是 http:// (没有SSL)。

使用此:

//
//  ChatpageViewController.m
//  ChatApp
//


#import "ChatpageViewController.h"


@interface ChatpageViewController ()
{

}

@end

@implementation ChatpageViewController
@synthesize receivedict,name,mobile;




-(void)viewWillAppear:(BOOL)animated
{

    self.collectionView.collectionViewLayout.springinessEnabled = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
       // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:YES animated:YES];
NSLog(@"%@",receivedict);
    name.text = [receivedict objectForKey:@"Name"];
    id.text =[receivedict objectForKey:@"Id"];



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSString *)senderId
{
    return [receivedict objectForKey:@"Id"];
}


- (NSString *)senderDisplayName
{

    return [receivedict objectForKey:@"Name"];
}

- (NSDate *)date
{
    return 18/03/2016;
}


- (void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date
{

    [JSQSystemSoundPlayer jsq_playMessageSentSound];

    JSQMessage *message = [[JSQMessage alloc] initWithSenderId:senderId
                                             senderDisplayName:senderDisplayName
                                                          date:date
                                                          text:text];
   // [demoData.messages addObject:message];
    [self finishSendingMessageAnimated:YES];


    NSLog(@"%@",message);
}



- (IBAction)cancelbtn:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end

而不是:

    $rest_url="http://do.convertapi.com/Pdf2Image";