Skip to content

Allowing flash (flv) files to be stored and embedded in a coppermine gallery

NOTICE: this is from April 2008. The information was accurate then and may still be accurate, but keep that in mind. Software changes. This info may need some adaptation. Also, see the disclaimer at the bottom of the post.

I have several websites for which I am responsible. On one site, I am building a new gallery site for storing pictures as well as sound and video clips. There are several good options for building a gallery site, and I have used more than one with success. For the site in question, I decided to use Coppermine, which is powerful, configurable, open source, and freely licensed using the GNU GPL.

I ran into a little snag that took some work to figure out. To help me remember what I did, I am blogging it here. Maybe someone else will find it useful as well.

Coppermine makes it very easy to store, embed and play lots of media files and formats. That is awesome. I found one that is not supported…the now common flv, or flash video. In fact, by default you can’t even upload a file with an flv extension. Bummer. Off to Google I ran.

I found several sites with ideas and info, but one was more useful than others. Even it required lots of reading and page turning. I decided to put all the info in one page for my easy reference, but the Coppermine Gallery forum deserves a link and the credit for this method. I’m just posting it, people there came up with it. That is an old thread, though, and things have changed since the first post. I had to read the whole thing to figure out what needed to happen to make this work, and that is the reason for this post, rather than just a bookmark in my personal web browser. Okay, here are the steps I took that got this working for me.

Note: get your site up and running, with the theme work complete before doing this. That will make your life a little easier.

1. Download and install the filetype editor MOD discussed here. The mod is included in the cpg1.4.x_plugin_pack_v3 package available on the SourceForge download page for Coppermine. I happened to upload all of the plugins to my website, and sorted them from there, ending up using only a handful. That was easier for me. You do it how you want to.

2. Run the plugin and make a new filetype using the following data; “flv – application/x-shockwave-flash – movie – Flash player”

3. Download the FLV Player from this site. Extract the archive locally and upload mediaplayer.swf and swfobject.js to your Coppermine site’s root directory.

4. I added the following code to my theme’s theme.php file, before the function theme_html_img_nav_menu().

Note: this code is available in a txt file here, which will probably be easier and better than trying to cut/paste from this page.

//** added by matthew to try to get flv play to work **
function theme_html_picture()
{
global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $USER;
global $album, $comment_date_fmt, $template_display_media;
global $lang_display_image_php, $lang_picinfo;

$pid = $CURRENT_PIC_DATA['pid'];
$pic_title = '';

if (!isset($USER['liv']) || !is_array($USER['liv'])) {
$USER['liv'] = array();
}
// Add 1 to hit counter
if (!USER_IS_ADMIN && !in_array($pid, $USER['liv']) && isset($_COOKIE[$CONFIG['cookie_name'] . '_data'])) {
add_hit($pid);
if (count($USER['liv']) > 4) array_shift($USER['liv']);
array_push($USER['liv'], $pid);
}

if($CONFIG['thumb_use']=='ht' && $CURRENT_PIC_DATA['pheight'] > $CONFIG['picture_width'] ){ // The wierd comparision is because only picture_width is stored
$condition = true;
}elseif($CONFIG['thumb_use']=='wd' && $CURRENT_PIC_DATA['pwidth'] > $CONFIG['picture_width']){
$condition = true;
}elseif($CONFIG['thumb_use']=='any' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
$condition = true;
}else{
$condition = false;
}

if ($CURRENT_PIC_DATA['title'] != '') {
$pic_title .= $CURRENT_PIC_DATA['title'] . "\n";
}
if ($CURRENT_PIC_DATA['caption'] != '') {
$pic_title .= $CURRENT_PIC_DATA['caption'] . "\n";
}
if ($CURRENT_PIC_DATA['keywords'] != '') {
$pic_title .= $lang_picinfo['Keywords'] . ": " . $CURRENT_PIC_DATA['keywords'];
}

if (!$CURRENT_PIC_DATA['title'] && !$CURRENT_PIC_DATA['caption']) {
template_extract_block($template_display_media, 'img_desc');
} else {
if (!$CURRENT_PIC_DATA['title']) {
template_extract_block($template_display_media, 'title');
}
if (!$CURRENT_PIC_DATA['caption']) {
template_extract_block($template_display_media, 'caption');
}
}

$CURRENT_PIC_DATA['menu'] = html_picture_menu(); //((USER_ADMIN_MODE && $CURRENT_ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID) || ($CONFIG['users_can_edit_pics'] && $CURRENT_PIC_DATA['owner_id'] == USER_ID && USER_ID != 0) || GALLERY_ADMIN_MODE) ? html_picture_menu($pid) : '';

if ($CONFIG['make_intermediate'] && $condition ) {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'normal');
} else {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
}

$image_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CONFIG['picture_width']);

$pic_title = '';
$mime_content = cpg_get_type($CURRENT_PIC_DATA['filename']);

if ($mime_content['content']=='movie' || $mime_content['content']=='audio') {

if ($CURRENT_PIC_DATA['pwidth']==0 || $CURRENT_PIC_DATA['pheight']==0) {
$CURRENT_PIC_DATA['pwidth']  = 320; // Default width

// Set default height; if file is a movie
if ($mime_content['content']=='movie') {
$CURRENT_PIC_DATA['pheight'] = 240; // Default height
}
}

$ctrl_offset['mov']=15;
$ctrl_offset['wmv']=45;
$ctrl_offset['swf']=0;
$ctrl_offset['rm']=0;
$ctrl_offset_default=45;
$ctrl_height = (isset($ctrl_offset[$mime_content['extension']]))?($ctrl_offset[$mime_content['extension']]):$ctrl_offset_default;
$image_size['whole']='width="'.$CURRENT_PIC_DATA['pwidth'].'" height="'.($CURRENT_PIC_DATA['pheight']+$ctrl_height).'"';
}


if ($mime_content['content']=='image') {
if (isset($image_size['reduced'])) {
$winsizeX = $CURRENT_PIC_DATA['pwidth']+5;  //the +'s are the mysterious FF and IE paddings
$winsizeY = $CURRENT_PIC_DATA['pheight']+3; //the +'s are the mysterious FF and IE paddings
$pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid=$pid&fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
$pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
$pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
$pic_html .= "</a>\n";
} else {
$pic_html = "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"\" /><br />\n";
}
} elseif ($mime_content['content']=='document') {
$pic_thumb_url = get_pic_url($CURRENT_PIC_DATA,'thumb');
$pic_html = "<a href=\"{$picture_url}\" target=\"_blank\" class=\"document_link\"><img src=\"".$pic_thumb_url."\" border=\"0\" class=\"image\" /></a>\n<br />";
} else {
$autostart = ($CONFIG['media_autostart']) ? ('true'):('false');

$players['WMP'] = array('id' => 'MediaPlayer',
'clsid' => 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" ',
'codebase' => 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ',
'mime' => 'type="application/x-mplayer2" ',
);
$players['RMP'] = array('id' => 'RealPlayer',
'clsid' => 'classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" ',
'codebase' => '',
'mime' => 'type="audio/x-pn-realaudio-plugin" '
);
$players['QT']  = array('id' => 'QuickTime',
'clsid' => 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ',
'codebase' => 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ',
'mime' => 'type="video/x-quicktime" '
);
$players['SWF'] = array('id' => 'SWFlash',
'clsid' => ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ',
'codebase' => 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ',
'mime' => 'type="application/x-shockwave-flash" '
);
$players['UNK'] = array('id' => 'DefaultPlayer',
'clsid' => '',
'codebase' => '',
'mime' => ''
);

if (isset($_COOKIE[$CONFIG['cookie_name'].'_'.$mime_content['extension'].'player'])) {
$user_player = $_COOKIE[$CONFIG['cookie_name'].'_'.$mime_content['extension'].'player'];
} else {
$user_player = $mime_content['player'];
}

// There isn't a player selected or user wants client-side control
if (!$user_player) {
$user_player = 'UNK';
}

if ($mime_content['content']=='movie' && $mime_content['mime']=='application/x-shockwave-flash') {
if ($CURRENT_PIC_DATA['pwidth']==0 || $CURRENT_PIC_DATA['pheight']==0) {
$CURRENT_PIC_DATA['pwidth']  = 640; // Default width
$CURRENT_PIC_DATA['pheight'] = 480; // Default height
}
$CURRENT_PIC_DATA['pwidth']-=26; // black bars on sides for me for some reason

$flv =  $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];

if($mime_content['extension']!='flv') {
$flvcheck = fopen($flv,"r");
$flv=fgets($flvcheck);
fclose($flvcheck);
}
$exxvars=str_replace($CONFIG['thumb_pfx'], $CONFIG['normal_pfx'], get_pic_url($CURRENT_PIC_DATA,'thumb'));
if(!file_exists($exxvars)) $exxvars=get_pic_url($CURRENT_PIC_DATA,'thumb');
$exxvars="â„‘=".$exxvars;
$pic_html = "<embed src=\"mediaplayer.swf\" width='".$CURRENT_PIC_DATA['pwidth']."' height='".$CURRENT_PIC_DATA['pheight']."' allowfullscreen=\"true\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"
flashvars=\"file=$flv$exxvars\"></embed>";

} else {

$player = $players[$user_player];

$pic_html  = '<object id="'.$player['id'].'" '.$player['classid'].$player['codebase'].$player['mime'].$image_size['whole'].'>';
$pic_html .= "<param name=\"autostart\" value=\"$autostart\" /><param name=\"src\" value=\"". $picture_url . "\" />";
$pic_html .= '<embed '.$image_size['whole'].' src="'. $picture_url . '" autostart="'.$autostart.'" '.$player['mime'].'></embed>';
$pic_html .= "</object><br />\n";

}
}

$CURRENT_PIC_DATA['html'] = $pic_html;
$CURRENT_PIC_DATA['header'] = '';
$CURRENT_PIC_DATA['footer'] = '';

$CURRENT_PIC_DATA = CPGPluginAPI::filter('file_data',$CURRENT_PIC_DATA);

$params = array('{CELL_HEIGHT}' => '100',
'{IMAGE}' => $CURRENT_PIC_DATA['header'].$CURRENT_PIC_DATA['html'].$CURRENT_PIC_DATA['footer'],
'{ADMIN_MENU}' => $CURRENT_PIC_DATA['menu'],
'{TITLE}' => bb_decode($CURRENT_PIC_DATA['title']),
'{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),
);

return template_eval($template_display_media, $params);
}
//** end added by matthew **

I have not tried them, but I have read that there are some changes you can make to your theme’s template.html file that will allow you to change the size of the video on site. If I am successful doing so, I will add that info in a comment here. Otherwise, this is all I have done, and the site in question now allows me to upload flash video and play it in the same way as an mpg or mov.

EDIT: March 9, 2009. I am no longer in charge of the site that I was working on when I wrote this. I’m leaving this post up in the hopes that it is helpful to others, but I don’t have a site available to use to help people troubleshoot. Sorry. You are still free and very welcome to post comments, questions, or tips, there just isn’t any guarantee that I will be able to help, but maybe someone else will. 🙂

44 Comments

  1. Oh, I just realized, at some point in the process you will need to go through the site settings and set up the file size and type permissions and parameters. I would do that first, but really it doesn’t matter when you do it, just that it gets done somewhere in the process.

  2. G.B.

    Hello, 2 questions:

    1. How do you add the code to OS X theme?
    2. Can you clarify your comment, maybe edit the blog post?

  3. I’ll do my best to answer.

    1. I’ve never used that theme, so what I am about to suggest has not been tested. However, you should be able to put the code I included above near the top of the theme.php file, after the headers. I suggest trying it right before this line
    // HTML template for sys_menu.

    2. What I am describing is a simple, but detailed process. Once Coppermine is installed on your site, go to the admin menu and click “config.” In the config area, look for the “files and thumbnails settings” and “files and thumbnails advanced settings” and adjust according to your server settings and personal taste/desires.

  4. G.B.

    I tried your recommendation but get an error message. Being not that proficient in PHP I am looking for some help:

    Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in //themes/mac_ox_x/theme.php on line 59

    Parse error: syntax error, unexpected T_STRING in //themes/mac_ox_x/theme.php on line 59

    which is this line:

    $pic_title .= $CURRENT_PIC_DATA[‘title’] . “\n”;

  5. Can you confirm that it this function is shown like this in the file?

    if ($CURRENT_PIC_DATA['title'] != ”) {
    $pic_title .= $CURRENT_PIC_DATA['title'] . “\n”;
    }

    If it is, then what is happening is there appears to be a character in the file’s title that the check is rejecting. Does the file that you are attempting to use have a \ in the title?

    Of course, I might be jumping ahead here. Do you get the error when you upload or attempt to view a file (which is what I am assuming here)? Or, are you getting this when trying to load the main page?

    EDIT: I just had another thought. I suppose the server could be rejecting the \ in the \n at the end of the line. That would be odd, but it could happen. Are you running your site on a Linux server, or a Windows server?

  6. G.B.

    The statement is correct, but I think I figured out the problem:

    “\n” should be “\n”

    note the double quotes are different. There are many instances of these and I am going line by line and replacing them.

  7. G.B.

    OK, looks like your portal automatically changes both the plain double and single quotes into open/close directional quotes. They throw an error in PHP.

  8. Doh! That would do it. I’ll see if I can format the text differently in the post to correct that. If I can’t, I’ll put it in a text file somewhere on my server with a link here for downloading. Sorry about that. I’m glad you figured it out.

  9. G.B.

    That was it! Grabbing the text from the TXT file worked. Thanks for your quick response, hopefully this will help everyone else.

  10. I have filed a bug report ticket with WordPress to see if there is something I am doing wrong, or if they would like to revise the code before the next bug fix release.

  11. Okay, changing the tags didn’t seem to change the final output. I have put the code quote here for anyone to download who wants it.

  12. Sheryl

    Thanks for this! Found it via google. You made your life easier and mine, as well! I was worried that after going through all the forum thread pages I’d either miss something or add something I didn’t need. Will try next chance I get!

  13. Sheryl: you are welcome! I’m glad you found it useful.

  14. Jimbo

    This is great, I was looking for a Flash Player for Coppermine – Question though, I was wondering if you knew how to Allow the Full Screen parameter?

    A useful tip, if you add a JPG with the same file name as the FLV file, it will become the Poster for the Video – maybe everyone already knows this.

  15. Hey Jimbo,

    First off, thanks for the tip! That’s pretty cool.

    Back to your question, I did not have to do anything in order for the full screen feature to work. When playing a video, I just click the “full screen” button on the embedded player and it just works.

  16. James

    Hi Matthew,

    Your plan sounds great, however I’m using igames theme and can not find (within theme.php) where I need to add your code as you describe above?

    I edit the file, but can not seem to find where I should paste the code.

    Can you please help me?

    Thanks

  17. Jimbo

    it took me a while to figure this out; I could not get the full screen button on my player. So you must have a different version of your code than I do.

    I did get the full screen button to show after I modified your code. There is a line in there that says; flashvars=\”file=$flv$exxvars which is the variable for the filename.

    Even though the code says allowfullscreen=true, that does not turn on the button, that just allows it to happen.

    In order to turn on the button I had to add &fullscreen=true to that piece of code, so it looks like this:

    flashvars=\”file=$flv$exxvars&fullscreen=true

    After I did that, the button magically appeared. I hate coding…

    There are several skins on jeroenwijering.com; I’ve tried replacing the mediaplayer.swf with the new ones from the skins,, they did not work very well.

    Any ideas on how to use a different skin..?

  18. James: I have only played with this using the default template, so I’m not sure what would need to be changed to use a different theme. All I can really suggest is to try pasting the code in different places in the file that seem reasonable and see what happens. You can’t actually hurt the rest of the site this way, and if you keep track of what you try, it is reversible.

    Jimbo: Dude! You are full of great ideas and helpful comments. Thank you for adding some more good info to the post. I appreciate it, and I’m sure others trying to do this will appreciate it as well.

  19. C Ellis

    Thanks for the info. It works great.
    I was wondering if I could assign a thumbnail for each video clip. As it is now all video uses the same standard “video” thumbnail.

  20. I have not been able to assign any thumbnail to video clips other than the standard one you mention, however, I will confess that I have not tried very hard. If I get some time soon, I’ll play around and see if I can do it easily. If I can, I’ll post an update.

  21. C Ellis

    Thanks, that would be awesome

  22. Chandresh Kesri

    Hi,

    I have tried your given steps and code. Even i have also used text file code

    but still i am getting error:

    Warning: Unexpected character in input: ” (ASCII=92) state=1 in /nfs/c02/h04/mnt/42596/domains/chambal.info/html/coppermine/themes/buckettheme/theme.php on line 2148

    Parse error: syntax error, unexpected T_STRING in /nfs/c02/h04/mnt/42596/domains/chambal.info/html/coppermine/themes/buckettheme/theme.php on line 2148

  23. Those errors are in your custom theme. Try comparing the theme.php file in your custom theme (named buckettheme) with the one in the standard/default theme.

  24. mark

    To get a thumbnail of your actual video file rather than the generic video thumb I used vlc player to make a screenshot from my video, resize it to thumbnail size then rename it as thumb_name-of-your-video.jpg and upload it to the same folder as your video is stored.

    Eg if your video was called beachparty.flv then name your the jpeg you want as your thumbnail as thumb_beachparty.jpg

    I would like some assistance, I have a mix of flv and mp4 files on my site and would like to be able to play them both through the flv player but cant see to find where to change the code to do this.
    If I change this line if($mime_content[‘extension’]!=’flv’) to if($mime_content[‘extension’]!=’mp4’) it will play the mp4 files but then the flv files wont play. does anyone know how to change the code to play them both?

  25. mark

    Hi, I tried your suggestion of adding the second code with mp4 instead of flv but then neither mp4 or flv files played. Any other ideas?

  26. Mark: try adding a second section after this one

    if($mime_content['extension']!=’flv’) {
    $flvcheck = fopen($flv,”r”);
    $flv=fgets($flvcheck);
    fclose($flvcheck);
    }

    that looks like this

    if($mime_content['extension']!=’mp4’) {
    $flvcheck = fopen($flv,”r”);
    $flv=fgets($flvcheck);
    fclose($flvcheck);
    }

    and see if having both in there does the trick. I think it should.

  27. Hmm. I am not able to play with the code on the site I mentioned in the post, so I’m making educated guesses with no way to test. Sorry about that.

    Another idea would be to make a new entry, like you did in step 2 above, only this time for mp4 files.

    It is also possible that a combination of the two methods may lead to success.

  28. Red

    after a little work, I sort of got this working except for one line that’s causing some issue. I tried to get the gallery.txt file, but it doesn’t seem to exist anymore. My issue is on this line:

    $exxvars=”â„’=’.$exxvars;

    The ”â„ is causing issues and I have no idea what is supposed to go there since I’m not a coder.

    Any help would be awesome.

  29. Sorry, the file changed locations and I forgot to update the link. I have done so in the earlier comment, and here is the link again.

  30. gil caboz

    I did all the modifications from plugin instructions.
    Unfortunately its not working. as you can see here
    *link broken and removed*
    The flv files uploaded fine but i get a white square in sted the flv player
    Please any help will be apreciated
    thankx]
    If you think you can help me please anwser me or send me a e-mail will apreceat Thankx
    Gil caboz

  31. I just went there. It worked perfectly for me. My guess is that your problem is in your web browser and the Flash plugin there, because the site seems fine. Congrats on the site: it is nice!

  32. BobSmith

    I’ve been trying to add a skin per the players website instruction
    If you’re using Object embed code, add this line to your player’s embed code (specifically within the flashvars=” ” variable):

    &skin=http://www.mysite.com/jwplayerskin/skinname.swf

    So your flash vars would look like this:

    flashvars=”height=250&width=400&file=afraid.flv&overstretch=true&skin=http://www.mysite.com/jwplayerskin/skinname.swf”

    but i cant seem to get that to work (obviously i sub’d my correct info in)

    Anyone play with that or have any luck getting the skins to work?

    Matthew – Thanks for putting this tut out there.

  33. John

    Great Mod and installs so quickly without any tweaking.
    I wish I had seen this before I spent days trawling through the forums.
    Matthew thanks for all your work.

  34. wally

    thanks for making this great page:

    how to make the movie to auto start?

    how to change the width and height of the video?

  35. I don’t administer a site with this installed at the moment, so I can’t play around to figure out autoplay for you. Sorry.

    However, the second question is pretty easy. Look for the following two lines in the code that you added to the theme.php file and modify them to your liking.

    $CURRENT_PIC_DATA[‘pwidth’] = 320; // Default width

    $CURRENT_PIC_DATA[‘pheight’] = 240; // Default height

  36. wally

    to make the movie autostart you need to replace this:

    flashvars=\”file=$flv$exxvars\”>”;

    with this

    flashvars=\”file=$flv&autostart=$autostart\”>”;

  37. christopher

    I added eveything as you posted.. my vidoe uploads fine.. but I dont see anything to view? When I riight click i get Adobe message and it says I have Flash installed? any ideas what is wrong:

  38. As best as I can tell from outside, your software seems to be installed fine. Are you sure the file works?

    EDIT: nevermind. I used the download link at the bottom of your page to download the file and it plays fine. Hmm.

    I’m sorry, that’s all I can think of at the moment.

  39. christopher

    Did it acutally show on the site? or only if you downloaded it? I can download it and watch it with AIR.. but I cant actually play it on my site..

    Thanks
    Christopher

  40. christopher

    Sorry also I was using the Fruity theme.. and just realized that default was set to classic.. could you try to view it now and see maybe? I uploaded everything to fruity..

    thanks
    Christopher

  41. It didn’t show on the site. I had to download the video, but by doing so I can confirm there is nothing wrong with the actual video file.

    In my experience, with stuff like this it is usually something small and silly that is missing. Unfortunately they can be tough to track down. I would start by checking the configuration bits in the theme file. The player doesn’t seem to be loading, so look for things that might cause that.

    Sorry I can’t be more help than that.

  42. christopher

    I know the problem.. the media player was named “player.swf” but code was pointing to “mediaplayer.swf”… works like a champ.. thanks for your help and the code you posted.. very easy!

    Christopher

  43. I’m so glad it got worked out. Isn’t it a great feeling when you figure out the problem and fix it? Congratulations.

  44. christopher

    Like you said “something small and silly” LOL..

Comments are closed.