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

时间:2011-06-07 11:13:32

标签: php file upload cdn

我正在尝试通过api在cdn服务器(hwcdn.net服务器)上传视频,但收到以下错误。 “ 0470文件名无效(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;
}

2 个答案:

答案 0 :(得分:0)

答案在错误中:文件名包含非法字符,您必须清除它,删除所有不是A-Z,a-z,0-9,-,_,',.的内容。

您可以使用preg_replace

答案 1 :(得分:0)

我认为这是错误的:

$directory="/folder path/"; 

hwcdn路径中不允许使用空格。