replace form input file with direct file upload

允我心安 提交于 2019-12-24 11:28:18

问题


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>

I already tried my best to digg deeper into cURL, but I'm not sure if this is what will help me here.


回答1:


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


来源:https://stackoverflow.com/questions/10918115/replace-form-input-file-with-direct-file-upload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!