I'm not sure if this is the right place to post this question, but it seems a little advanced for the General Discussion.
I'm using CMS1.4.1 on linux server running PHP 5 as CGI. I'm also using the friendly URL option.
Scenario:
This website showcases lyrics. Some of the lyrics have audio. The audio files will reside in uploads/audio/ directory. I don’t have the client’s audio yet, so I created a test page called heatwave http://obadiahlyrics.com/lyrics/heatwave.php and uploaded Heatwave.mp3 to uploads/audio. The image link does not show up. I know the file can play cause it shows up on my playlist here http://obadiahlyrics.com/audio.php
What I wanted the code snippet to do is show an audio image that links to the mp3 if the mp3 file exists or show nothing if it does not. The .mp3 needs to replace the image when the image is clicked and play automatically.
I created a user defined tag and placed the following code in it:
Code: Select all
/*
gets the full path to the file and strips out everything but the filename
In this case has to be .php files
@return - returns just the filename without the extension.
*/
function getMyFileName() {
$path = $_SERVER['PHP_SELF'];
$bname = basename($path,'.php');
return $bname;
}
function formatForFindFile($fn) {
$xp = explode("-",$fn); // turn php filename into an array of words eg: dot-ball => array('dot','ball');
foreach($xp as $k => $v) {
$v2 = strtolower($v); // make sure everything is lowercase first
$xp[$k] = ucfirst($v2); // uppercase the first letter for each word and assign it back into the array
}
$newFN = implode(" ",$xp); // turn array back into string with spaces: eg: "Dot Ball"
return $newFN;
}
/*
gets the base filename of this file and appends .mp3 to it and returns to the caller
*/
function getMp3FileLink() {
$fileName = getMyFileName();
$fileName = formatForFindFile($fileName);
$fileName .= ".mp3";
$serverPathToFile = "../uploads/audio";
$browserPathToFile = "/uploads/audio";
if(is_file($serverPathToFile."/".$fileName)) {
$output = '<a href="'.$browserPathToFile.'/'.$fileName.'" title="Play this audio"><img src="/uploads/images/playAudio.gif"></a>';
return $output;
} else {
return "Hello";
}
}
$syn = getMp3FileLink();
/* smarty stuff */
$smarty->assign('mp3Link', $syn);
Code: Select all
<div class="audiobtn">{$mp3Link}</div>
I know this is probably a file path issue, but I can't seem to figure it out. I'm hoping a CMS php guru can make a detailed suggestion? I'm not a coder, i got the script for a colleague, but he has no experience with CMSMS.
Much appreciate any efforts.