用直接文件上传替换表单输入文件
我正在使用php的服务器侧Youtube上传器。使用此脚本,我上传视频文件成功到Youtube。但是,我不想手动选择文件,但我想上传一个已经在我的服务器上的文件。
我知道文件名/ -path(和视频base64编码同样,如果这是有帮助的任何方式),我拥有所有的钥匙和令牌是需要的Youtube。但是,我不知道如何将所有这些信息转换为合适的http-post。
I'm working on a serverside Youtube uploader in php. Using this script I upload the video file successfully to Youtube. However, I don't want to manually select the file, but I want to upload a file that is already on my server. I know the filename/-path (and have the video base64-coded likewise if this was helpful in any way), and I have all keys and tokens that are needed for Youtube. However, I don't know how to transform all this information into the appropriate 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,但我不知道这是什么
I already tried my best to digg deeper into cURL, but I'm not sure if this is what will help me here.
根据您提供的网址找到的脚本,我会先尝试:
Based on the script found at the url you provided I would try this first:
$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);