2012-08-24 154 views
1

我使用的視頻腳本,我想隨機的網址大拇指: 有定義爲拇指目錄和url全局變量一個的common.php:隨機化的子服務器

define('THUMB_FILES_DIR',' '); 
define('THUMB_FILES_URL',''); 
define('THUMBS_DIR',THUMB_FILES_DIR.'/thumbs'); 
define('THUMBS_URL',THUMB_FILES_URL.'/thumbs'); 

,並獲得功能拇指是:

/** 
    * FUNCTION USED TO GET THUMBNAIL 
    * @param ARRAY video_details, or videoid will also work 
    */ 

function get_thumb($vdetails,$num='default',$multi=false,$count=false,$return_full_path=true,$return_big=true,$size=false){ 
     global $db,$Cbucket,$myquery; 
     $num = $num ? $num : 'default'; 
     #checking what kind of input we have 
     if(is_array($vdetails)) 
     { 
      if(empty($vdetails['title'])) 
      { 
       #check for videoid 
       if(empty($vdetails['videoid']) && empty($vdetails['vid']) && empty($vdetails['videokey'])) 
       { 
        if($multi) 
         return $dthumb[0] = default_thumb(); 
        return default_thumb(); 
       }else{ 
        if(!empty($vdetails['videoid'])) 
         $vid = $vdetails['videoid']; 
        elseif(!empty($vdetails['vid'])) 
         $vid = $vdetails['vid']; 
        elseif(!empty($vdetails['videokey'])) 
         $vid = $vdetails['videokey']; 
        else 
        { 
         if($multi) 
          return $dthumb[0] = default_thumb(); 
         return default_thumb(); 
        } 
       } 
      } 
     }else{ 
      if(is_numeric($vdetails)) 
       $vid = $vdetails; 
      else 
      { 
       if($multi) 
        return $dthumb[0] = default_thumb(); 
       return default_thumb(); 
      } 
     } 


     #checking if we have vid , so fetch the details 
     if(!empty($vid)) 
      $vdetails = $myquery->get_video_details($vid); 

     if(empty($vdetails['title'])) 
     { 
      if($multi) 
        return default_thumb(); 
      return default_thumb(); 
     } 

     #Checking if there is any custom function for 
     if(count($Cbucket->custom_get_thumb_funcs) > 0) 
     { 

      foreach($Cbucket->custom_get_thumb_funcs as $funcs) 
      { 

       //Merging inputs 
       $in_array = array(
       'num' => $num, 
       'multi' => $multi, 
       'count' => $count, 
       'return_full_path' => $return_full_path, 
       'return_big' => $return_big 
       ); 
       if(function_exists($funcs)) 
       { 
        $func_returned = $funcs($vdetails,$in_array); 
        if($func_returned) 
        return $func_returned; 
       } 
      } 
     } 

     #get all possible thumbs of video 
     if($vdetails['file_name']) 
     $vid_thumbs = glob(THUMBS_DIR."/".$vdetails['file_name']."*"); 
     #replace Dir with URL 
     if(is_array($vid_thumbs)) 
     foreach($vid_thumbs as $thumb) 
     { 
      if(file_exists($thumb) && filesize($thumb)>0) 
      { 
       $thumb_parts = explode('/',$thumb); 
       $thumb_file = $thumb_parts[count($thumb_parts)-1]; 

       if(!is_big($thumb_file) || $return_big) 
       { 
        if($return_full_path) 
         $thumbs[] = THUMBS_URL.'/'.$thumb_file; 
        else 
         $thumbs[] = $thumb_file; 
       } 
      }elseif(file_exists($thumb)) 
       unlink($thumb); 
     } 

     if(count($thumbs)==0) 
     { 
      if($count) 
       return count($thumbs); 
      if($multi) 
        return $dthumb[0] = default_thumb(); 
      return default_thumb(); 
     } 
     else 
     { 
      if($multi) 
       return $thumbs; 
      if($count) 
       return count($thumbs); 

      //Now checking for thumb 
      if($num=='default') 
      { 
       $num = $vdetails['default_thumb']; 
      } 
      if($num=='big' || $size=='big') 
      { 

       $num = 'big-'.$vdetails['default_thumb']; 
       if(!file_exists(THUMBS_DIR.'/'.$vdetails['file_name'].'-'.$num.'.jpg')) 
       $num = 'big';    
      } 

      $default_thumb = array_find($vdetails['file_name'].'-'.$num,$thumbs); 

      if(!empty($default_thumb)) 
       return $default_thumb; 
      return $thumbs[0]; 
     } 

    } 

    /** 
    * Function used to check weaether given thumb is big or not 
    */ 
    function is_big($thumb_file) 
    { 
     if(strstr($thumb_file,'big')) 
      return true; 
     else 
      return false; 
    } 
    function GetThumb($vdetails,$num='default',$multi=false,$count=false) 
    { 

     return get_thumb($vdetails,$num,$multi,$count); 
    } 

    /** 
    * function used to get detaulf thumb of ClipBucket 
    */ 
    function default_thumb() 
    { 
     if(file_exists(TEMPLATEDIR.'/images/thumbs/processing.png')) 
     { 
      return TEMPLATEURL.'/images/thumbs/processing.png'; 
     }elseif(file_exists(TEMPLATEDIR.'/images/thumbs/processing.jpg')) 
     { 
      return TEMPLATEURL.'/images/thumbs/processing.jpg'; 
     }else 
     return BASEURL.'/files/thumbs/processing.jpg'; 
    } 

我想URL隨機拇指從服務器D是圖像這樣 http://img[random number].domainname

,如果我創建了大拇指URL的數組中的值,然後將結果洗牌到

define('THUMB_FILES_DIR',' '); 
define('THUMB_FILES_URL',''); 

所有的大拇指將具有相同的URL值 怎麼做纔能有傳遞到HTML頁面不同的值?

+1

您將需要通過.htaccess查看URL重寫。 –

+0

你是這麼認爲的,因爲它在php代碼 –

+0

中更加簡單或不可能,原因是什麼?不允許客戶端緩存? – feeela

回答

-1

而不是使用全局變量的拇指url,你需要使用一個函數。然後它可以在被調用時隨機選擇一個URL。

+0

我不能添加一個參數到現有的功能,chage網址? –

+0

也許允許'$ num ='random'',然後洗牌'glob'的結果。 – Barmar