视频上传到机架空间失败,无法显示图像

时间:2012-04-04 17:58:22

标签: php twitter rackspace

所以我为tweetbot做了自定义媒体上传服务。图片上传得很好,网址由tweetbot返回和发布。但是,当我尝试上传视频时,它会检索到网址,但会发生这种情况:

http://c0728267.cdn2.cloudfiles.rackspacecloud.com/1333560894-movie.mp4

注意顶部文字前面的图像?然而,它是一个视频。我究竟做错了什么?

以下是上传过程的代码

$oauthecho = new TwitterOAuthEcho();
$oauthecho->userAgent = 'dpkgme test app';
$oauthecho->setCredentialsFromRequestHeaders();

if ($oauthecho->verify()) {      

 // Verification was a success, we should be able to access the user's Twitter info from the responseText.
 $userInfo = json_decode($oauthecho->responseText, true);
 $twitterId = isset($userInfo['id']) ? $userInfo['id'] : null;


                    $tweet = $_POST['message'];

                    error_reporting(E_ALL);
                    ini_set('display_errors', 1);

                    // include the API
                    require("cloudfiles.php") ;

                    // cloud info
                    $username = ''; // username
                    $key ='' ; // api key
                    $container = ''; // container name

                    ob_start();


                    $localfile = $_FILES['media']['tmp_name'];
                    $filename = $_FILES['media']['name'];
                    $nf = time().'-'.$filename; 


                    ob_flush();

                    // Connect to Rackspace
                    $auth = new CF_Authentication($username, $key);
                    $auth->authenticate();
                    $conn = new CF_Connection($auth);

                    // Get the container we want to use
                    $container = $conn->create_container($container);

                    // store file information

                    ob_flush();

                    // upload file to Rackspace
                    $object = $container->create_object($nf);
                    $object->load_from_filename($localfile);

                    $uri = $container->make_public();
                    //print "Your URL is: " . $object->public_uri();

                    $imagePageUrl = $object->public_uri();


                    ob_end_flush();


$link = 'http://c0728267.cdn2.cloudfiles.rackspacecloud.com/'.$nf ; 

$shortenedurl = file_get_contents('http://gl.gy/index.php?url='.$link);
$keys = parse_url($shortenedurl); // parse the url
    $path = explode("/", $keys['path']); // splitting the path
    $last = end($path); // get the value of the last element 


    echo '<mediaurl>http://gl.gy/'.$last.'</mediaurl>';

1 个答案:

答案 0 :(得分:0)

解决。我添加了内容类型检测。现在工作正常。