如何将视频文件上传到cdn服务器上?

发布于 2024-11-14 09:25:36 字数 1353 浏览 1 评论 0原文

我试图通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

oО清风挽发oО 2024-11-21 09:25:36

我认为这是错误的:

$directory="/folder path/"; 

hwcdn 路径中不允许有空格。

I think this is wrong :

$directory="/folder path/"; 

The space is not allowed in hwcdn paths.

ゃ懵逼小萝莉 2024-11-21 09:25:36

答案就在错误中:文件名包含非法字符,您必须对其进行清理,删除所有不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文