用直接文件上传替换表单输入文件

时间:2012-06-06 16:18:16

标签: php curl upload

我正在使用php中的服务器端Youtube上传器。使用this script我将视频文件成功上传到Youtube。但是,我不想手动选择文件,但我想上传已经在我的服务器上的文件。 我知道文件名/ -path(并且如果这对任何方式都有帮助,也会同时使用视频base64编码),并且我拥有Youtube所需的所有键和标记。但是,我不知道如何将所有这些信息转换为适当的http-post。

<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data">
   <input id="file" type="file" name="file"/>
   <input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
   <input type="submit" value="go" />
</form>

我已经尽力深入挖掘cURL,但我不确定这是否会对我有所帮助。

1 个答案:

答案 0 :(得分:0)

根据您提供的网址上找到的脚本,我会先尝试一下:

$ch = curl_init($response->url."?nexturl=".urlencode($nexturl));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
    "file"=>"@/path/to/file.avi",
    "token"=>$response->token
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);
相关问题