如何将视频文件上传到cdn服务器上?
我试图通过 api 在 cdn 服务器(hwcdn.net 服务器)上上传视频,但出现以下错误。 “ 0470 文件名无效(AZ,az,0-9,-,_,',.)”
//PHP example code for calling an action: $action = "UF"; //get system info $user = "xxxxxx"; //my StrikeTracker user name $pass = "xxxxxx"; //my StrikeTracker password $apiKey ="xxxxxxxxxxxxxxxxxxxx"; //my API Key $md5pass = md5($pass); $queryString = "action=$action&user=$user&key=$apiKey&password=$md5pass"; $token =md5($queryString); $directory="/folder path/"; $Filedata="testingvideo.flv"; echo $apiQuery = "action=$action&user=$user&token=$token&directory=$directory&Filedata=$Filedata"; $host="http://st-api.hwcdn.net/index.php"; echo do_post_request($host,$apiQuery); function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; }
I am trying to upload video on cdn server(hwcdn.net server) through api, but getting the following error .
" 0470 Invalid file name (A-Z,a-z,0-9,-,_,',.) "
//PHP example code for calling an action: $action = "UF"; //get system info $user = "xxxxxx"; //my StrikeTracker user name $pass = "xxxxxx"; //my StrikeTracker password $apiKey ="xxxxxxxxxxxxxxxxxxxx"; //my API Key $md5pass = md5($pass); $queryString = "action=$action&user=$user&key=$apiKey&password=$md5pass"; $token =md5($queryString); $directory="/folder path/"; $Filedata="testingvideo.flv"; echo $apiQuery = "action=$action&user=$user&token=$token&directory=$directory&Filedata=$Filedata"; $host="http://st-api.hwcdn.net/index.php"; echo do_post_request($host,$apiQuery); function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是错误的:
hwcdn
路径中不允许有空格。I think this is wrong :
The space is not allowed in
hwcdn
paths.答案就在错误中:文件名包含非法字符,您必须对其进行清理,删除所有不是
AZ,az,0-9,-,_,',.
的内容。您可以使用
preg_replace
。The answer is in the error: the filename contains illegal chars, you have to sanitize it removing everything that is not
A-Z,a-z,0-9,-,_,',.
.You can use
preg_replace
.