2013-01-21 42 views
4

我有一個腳本可以在webroot之外上傳。通過網站我然後鏈接用戶的圖像文件等在webroot之外嵌入flv和swf

因此,對於圖像的鏈接將是:

media.php?file=nameoffile.jpg&user=userid&folder=images 

這則用來顯示圖像:

<img src="media.php?file=nameoffile.jpg&user=userid&folder=images" width="100" border="0"> 

該作品罰款的圖像和提供鏈接下載文件。我使用ffmpeg將所有允許的視頻類型轉換爲flv(這些視頻經過測試,效果很好),但是當我嘗試嵌入flv視頻時,它永遠不會工作(它與直接該文件的鏈接只是不通過media.php)。如果可能的話,我還想嵌入.swf。

我使用jwplayer嵌入(工作原理與文件的直接鏈接只是沒有通過忽略原始)

 <!-- START OF THE PLAYER EMBEDDING TO COPY-PASTE --> 
      <object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="328" height="200"> 
      <param name="movie" value="player.swf" /> 
      <param name="allowfullscreen" value="true" /> 
      <param name="allowscriptaccess" value="always" /> 
      <param name="flashvars" value="media.php?file=nameoffile.flv&user=userid&folder=videos" /> 
      <embed 
       type="application/x-shockwave-flash" 
       id="player2" 
       name="player2" 
       src="player.swf" 
       width="328" 
       height="200" 
       allowscriptaccess="always" 
       allowfullscreen="true" 
       flashvars="file=media.php?file=nameoffile.flv&user=userid&folder=videos" 
      /> 
      </object> 
      <script type="text/javascript" src="jwplayer.js"></script> 
      <!-- END OF THE PLAYER EMBEDDING --> 

這裏是忽略原始

 $path_parts = pathinfo($_SERVER['REQUEST_URI']); 
     $file = basename(urldecode($_GET['file'])); 
     $user = basename(urldecode($_GET['user'])); 
     $folder = basename(urldecode($_GET['folder'])); 
     $ext = pathinfo($file, PATHINFO_EXTENSION); 

     $fileDir = 'pathoutsidewebroot'; 
     $filePath = $fileDir . $file; 

     switch(
     $ext) { 
      case "flv": $ctype="video/x-flv"; break; 
      // adobe 
      case "pdf": $ctype="application/pdf"; break; 
      // ms office 
      case "doc": $ctype="application/msword"; break; 
      case "rtf": $ctype="application/rtf"; break; 
      case "xls": $ctype="application/vnd.ms-excel"; break; 
      case "ppt": $ctype="application/vnd.ms-powerpoint"; break; 
      // open office 
      case "odt": $ctype="application/vnd.oasis.opendocument.text"; break; 
      case "ods": $ctype="application/vnd.oasis.opendocument.spreadsheet"; break; 
      default: $ctype = "application/force-download"; break; 
} 

     if(in_array($ext, $valid_formats_vid)){ 
      if (file_exists($filePath)) { 
       header('Content-Type: ' . mime_content_type($filePath)); 
       header('Content-Length: ' . filesize($filePath)); 
       readfile($filePath); 
     } 
     } 

     else if(in_array($ext, $valid_formats_img)) { 
      if (file_exists($filePath)) { 
       header('Content-Type: ' . mime_content_type($filePath)); 
       header('Content-Length: ' . filesize($filePath)); 
       readfile($filePath); 
      } 
     } 
     else if(in_array($ext, $valid_formats_docs)) { 
        if (file_exists($filePath)) 
        { 
      header("Pragma: public"); 
      header("Expires: 0"); 
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
      header("Cache-Control: private",false); 
      header("Content-Type: $ctype"); 
      header("Content-Disposition: attachment; filename=\"".basename($filePath)."\";"); 
      header("Content-Transfer-Encoding: binary"); 
      header("Content-Length: "[email protected]($filePath)); 
      set_time_limit(0); 
      @readfile($filePath) or die("File not found.");     } 
     } 

頭from embed that is through media.php

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Connection:Keep-Alive 
Content-Disposition:filename=encoded_2012-10-19_22.37.09_1359032866.flv 
Content-Length:0 
Content-Type:video/x-flv 
Date:Thu, 24 Jan 2013 16:26:32 GMT 
Expires:Thu, 19 Nov 1981 08:52:00 GMT 
Keep-Alive:timeout=5, max=88 
Pragma:no-cache 
Server:Apache/2.2.20 (Ubuntu) 
X-Powered-By:PHP/5.3.6-13ubuntu3.8 
從直接的聯繫

頭到文件(正常工作的那個)

Accept-Ranges:bytes 
Connection:Keep-Alive 
Content-Length:2428614 
Content-Type:video/x-flv 
Date:Thu, 24 Jan 2013 16:23:54 GMT 
ETag:"26ca3d8-250ec6-4d4087c796500" 
Keep-Alive:timeout=5, max=100 
Last-Modified:Thu, 24 Jan 2013 13:07:00 GMT 
Server:Apache/2.2.20 (Ubuntu) 

設法通過向忽略原始改變它這個(但仍然沒有工作)

  header("Content-Type: $ctype"); 
      header('Content-Length: ' . filesize($filePath)); 
      header('Accept-Ranges: bytes'); 
      $now = time(); 
      $then = gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now + 365*86440); 
      header("Expires: $then"); 
      ob_clean(); 
      flush(); 
      readfile($filePath); 



Accept-Ranges:bytes 
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Connection:Keep-Alive 
Content-Length:2428614 
Content-Type:video/x-flv 
Date:Thu, 24 Jan 2013 16:44:18 GMT 
Expires:Fri, 24 Jan 2014 20:47:38 GMT 
Keep-Alive:timeout=5, max=79 
Pragma:no-cache 
Server:Apache/2.2.20 (Ubuntu) 
X-Powered-By:PHP/5.3.6-13ubuntu3.8 

回答

1

我設法得到它與下面的工作,我還包括玩家拇指圖像(這是採取通過上傳的ffmpeg):

header("Content-Type: $ctype"); 
header('Content-Length: ' . filesize($filePath)); 
header('Accept-Ranges: bytes'); 
$now = time(); 
$then = gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now + 365*86440); 
header("Expires: $then"); 
ob_clean(); 
flush(); 
readfile($filePath); 


$flv_path = 'media.php?file='.$row['cur_image'].'&folder=videos&user='.$row["posted_by"]; 

$thumb = pathinfo($row['cur_image']); 
$thumb_path = 'media.php?file='.$thumb['filename'].'.jpg&folder=videos&user='.$row["posted_by"]; 
?>   


<!-- START OF THE PLAYER EMBEDDING TO COPY-PASTE --> 
<div id="mediaplayer_<?php echo $row['p_id']; ?>">JW Player goes here</div>       
<script type="text/javascript"> 
         jwplayer("mediaplayer_<?php echo $row['p_id']; ?>").setup({ 
          flashplayer: "jwplayer/jwplayer.flash.swf", 
          file: "<?php echo $flv_path; ?>", 
          image: "<?php echo $thumb_path; ?>", 
          controlbar: "bottom", 
          width: "380", 
          height: "200", 
          primary: "flash", 
          type: "mp4", 
          controls: true, 
          allowscriptaccess: 'always' 
         }); 
</script> 
<!-- END OF THE PLAYER EMBEDDING --> 
1

問題在這裏:

flashvars="file=media.php?file=nameoffile.flv&user=userid&folder=videos" 

flashvars收到查詢st環,所以這被解釋爲

file : media.php?file=nameoffile.flv 
user : userid 
folder : videos 

您需要進行urlencode文件參數:

flashvars="file=media.php?file=nameoffile.flv&amp;user=userid&amp;folder=videos" 
+0

將這項工作? ------ Flash變數=「文件= <?php echo urlencode('media.php?file ='。$ row ['cur_image']。'&folder = embed&user ='。$ row [「posted_by」]); ?>「 – Codded

+0

爲什麼你不試試它?)它應該工作,是的。 –

+0

是的,我做了,但它不工作...只是想知道我是否正確。根據這個HTTP輸出的URL看起來不錯://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12536/configuration-options – Codded