cURL 无法在 scribd 上上传文件
我想使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您至少有一个语法错误(curlopt_url 行中的
_
)。您是否在 exec() 调用后检查了curl 错误?另外,您的评论表明文件字段的名称是“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?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.