cURL 无法在 scribd 上上传文件

发布于 2024-12-27 11:49:11 字数 714 浏览 0 评论 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);
?>

i want to upload a file to scribd.com using curl,

please help me guys,

i am trying this code:

<?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);
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的巷 2025-01-03 11:49:11

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

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

另外,您的评论表明文件字段的名称是“file_box”,但您仅使用“file”作为上传字段。您必须符合 scribd 的预期。你不能只是把一个文件扔到他们面前并指望它能起作用。您正在使用curl 来重新创建浏览器的功能,这意味着您必须复制执行基于浏览器的正常上传时发送的所有字段/数据。

you've got at least one syntax error (_ in your curlopt_url line). Have you checked for curl errors after the exec() call?

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

as well, your comment indicates the file field's name is "file_box", but you're using just "file" as your upload field. You must match what scribd is expecting. You can't just throw a file over their way and expect it to work. You're using curl to recreate what a browser would do, which means you have to duplicate all the fields/data that gets sent when a normal browser-based upload is performed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文