0

我想使用 curl 将文件上传到 scribd.com,

请帮帮我,伙计们,

我正在尝试这段代码:

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, _'http://www.scribd.com/upload/supload');
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="file_box">
    $post = array(
    $path=getcwd(); //absolute path
    $post = array(
        "file"=>"@".$path."/test.txt",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch);
?>
4

1 回答 1

0

您至少有一个语法错误(_在您的 curlopt_url 行中)。你在 exec() 调用后检查过 curl 错误吗?

$response = curl_exec($ch);
if ($response === false) {
   die(curl_error($ch));
}

同样,您的评论表明文件字段的名称是“file_box”,但您仅使用“文件”作为上传字段。您必须符合 scribd 的期望。您不能只是将文件扔给他们并期望它起作用。您正在使用 curl 重新创建浏览器将执行的操作,这意味着您必须复制执行基于浏览器的正常上传时发送的所有字段/数据。

于 2012-01-17T00:24:53.980 回答