我正在尝试在php中创建一个str_replace,我将从db输出中删除任何类型的文件扩展名。
完整的PHP脚本
<?php
/* YOU CAN PLACE YOUR CUSTOM FUNCTIONS IN HERE TO MAKE UPDATING EASIER. THEY WILL NOT BE OVERWRITTEN BY UPDATES */
//display video player
function displayPlayerHtml5($rrow, $width = 590, $height = 475, $skipAutoPlay = false) {
global $domain;
global $licenseKeyHTML5;
global $basehttp;
global $video_url;
global $player_streamer;
global $encodeTrailer;
global $modsec_enabled;
global $adultCentroPassword;
global $player_watermark_url;
global $video_path;
if ($player_streamer == 'rtmp') {
unset($video_url);
}
if (strpos($width, '%') === false) {
$width = $width . 'px';
}
if (strpos($height, '%') === false) {
$height = $height . 'px';
}
if ($rrow['embed']) {
echo resizeEmbedded($rrow['embed'], $width, $height);
} else {
if ($rrow['hotlinked']) {
if (stripos($rrow['hotlinked'], 'adultcentro') !== false) {
$defaultFile = $basehttp . '/index.php' . urlencode('?controller=adultCentroGetLink&id=' . str_replace('adultcentro', '', $rrow['hotlinked']) . '&hash=' . md5($adultCentroPassword . str_replace('adultcentro', '', $rrow['hotlinked']) . $_SERVER['REMOTE_ADDR']));
} else {
$defaultFile = $rrow['hotlinked'];
}
} else {
$video_file = $rrow['filename'];
$subdir = $rrow[filename][0] . '/' . $rrow[filename][1] . '/' . $rrow[filename][2] . '/' . $rrow[filename][3] . '/' . $rrow[filename][4] . '/';
if ($encodeTrailer && $rrow['trailer_filename'] && !$_SESSION['userid']) {
$rrow['filename'] = $rrow['trailer_filename'];
}
if ($modsec_enabled) {
$defaultFile = getMediaLink($subdir . $rrow['filename']);
} else {
$defaultFile = $video_url . '/' . $subdir . $rrow['filename'];
$FileWebmpath = $video_path . '/' . $subdir . str_replace(".mp4",".webm",$rrow['filename']);
$FileFLVpath = $video_path . '/' . $subdir . str_replace(".mp4",".flv",$rrow['filename']);
}
}
if (file_exists($FileWebmpath)) {
$FileWebm = ($video_url . '/' . $subdir . str_replace(".mp4",".webm",$rrow['filename']));
} else {}
if (file_exists($FileFLVpath)) {
$FileFLV = ($video_url . '/' . $subdir . str_replace(".mp4",".flv",$rrow['filename']));
} else {}
?>
<? $subtitle = ($video_path . '/' . $subdir . $rrow['filename']) . ('-da.vtt');
if (file_exists($subtitle)) {
$subtitles = ($video_url . '/' . $subdir . $rrow['filename']) . ('-da.vtt');
} else {
}
?>
<div id="with-subtitles"
class="minimalist flowplayer play-button color-light"
preload="metadata"
data-swf="//<? echo $domain; ?>/includes/html5/flowplayer.swf"
data-key="<? echo $licenseKeyHTML5; ?>"
data-logo="<? echo $player_watermark_url; ?>"
data-splash="true"
data-embed="false"
data-fullscreen="true"
data-poster="<? echo getThumbUrl($rrow['orig_filename'],$rrow['filename'],$rrow['main_thumb'],true); ?>"
data-analytics="UA-31104891-3"
>
<video>
<source type="video/mp4" src="<? echo $defaultFile; ?>">
<source type="video/webm" src="<? echo $FileWebm; ?>">
<source type="video/flash" src="<? echo $FileFLV; ?>">
<track kind="subtitles" srclang="da" label="Dansk" src="<? echo $subtitles; ?>">
</video>
</div>
<?
}
}
//display video player Admin Interface
function displayPlayerHtml5adm($rrow, $width = 450, $height = 300, $skipAutoPlay = false) {
global $domain;
global $licenseKeyHTML5;
global $basehttp;
global $video_url;
global $player_streamer;
global $encodeTrailer;
global $modsec_enabled;
global $adultCentroPassword;
global $player_watermark_url;
if ($player_streamer == 'rtmp') {
unset($video_url);
}
if (strpos($width, '%') === false) {
$width = $width . 'px';
}
if (strpos($height, '%') === false) {
$height = $height . 'px';
}
if ($rrow['embed']) {
echo resizeEmbedded($rrow['embed'], $width, $height);
} else {
if ($rrow['hotlinked']) {
if (stripos($rrow['hotlinked'], 'adultcentro') !== false) {
$defaultFile = $basehttp . '/index.php' . urlencode('?controller=adultCentroGetLink&id=' . str_replace('adultcentro', '', $rrow['hotlinked']) . '&hash=' . md5($adultCentroPassword . str_replace('adultcentro', '', $rrow['hotlinked']) . $_SERVER['REMOTE_ADDR']));
} else {
$defaultFile = $rrow['hotlinked'];
}
} else {
$video_file = $rrow['filename'];
$subdir = $rrow[filename][0] . '/' . $rrow[filename][1] . '/' . $rrow[filename][2] . '/' . $rrow[filename][3] . '/' . $rrow[filename][4] . '/';
if ($encodeTrailer && $rrow['trailer_filename'] && !$_SESSION['userid']) {
$rrow['filename'] = $rrow['trailer_filename'];
}
if ($modsec_enabled) {
$defaultFile = getMediaLink($subdir . $rrow['filename']);
} else {
$defaultFile = $video_url . '/' . $subdir . $rrow['filename'];
}
}
?>
<link rel="stylesheet" type="text/css" href="//<? echo $domain; ?>/includes/html5/skin/minimalist.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="//<? echo $domain; ?>/includes/html5/flowplayer.min.js"></script>
<div class="flowplayer play-button color-light"
style="max-width: 450px; max-hight: 300px;"
data-swf="//<? echo $domain; ?>/includes/html5/flowplayer.swf"
preload="metadata"
data-key="<? echo $licenseKeyHTML5; ?>"
data-splash="true"
data-fullscreen="true"
data-embed="false"
data-poster="<? echo getThumbUrl($rrow['orig_filename'],$rrow['filename'],$rrow['main_thumb'],true); ?>">
<video>
<source type="video/mp4" src="<? echo $defaultFile; ?>">
</video>
</div>
<?
}
}
&GT;
我希望它替换.flv .mp4 .webm等任何固定值.webm和.flv .....如果文件确实存在的话。因此必须进行文件检查。
我无法操纵/添加db to db to features upgrade ..
前几个。来自db 54b1d96b89943.flv的文件名5547e6f7b2694Politijagtmedover200km_t- [720p] .mp4有人可以帮助我吗?
答案 0 :(得分:2)
正如我从你的问题中所理解的那样。你可以试试这个
$fileExtensions=array(original file extensions here);
$replacement=array(replacement extensions);
然后
if(file_exists($fileName)){ str_replace($fileExtensions, $replacement, $fileName);
}
答案 1 :(得分:0)
while ( substr($filename,-1)!=".") ){
$filename = substr($filname,0,-1);
}
$filename = substr($filname,0,-1);
$newext=".flv";
$newfilename = $filename.$newext;