Multimedia: Copy SWF file into a non-protected directory

When using the multimedia CP to display a Flash swf file and using the “internal file” option (a swf file uploaded via the backend), the file doesn't display/load in the front end.

The reason for this behavior is the protection of the directory ”/filearchive/” by an htaccess file.

There are two solutions for this problem:

1st Disable the htaccess file (no good idea)
2nd Script: Copy the requested file into an unprotected directory and provide it from this place

I want to talk about the second method.



During the CP call the script determines the relevant file name from the HTML source code and looks for the existance of the requested file within the non-protected directory. If this file does not exist there, that file will be copied from ”/filearchive/” to ”/content/tmp/” and the HTML source code for the output will be generated.

<note> If the original file in ”/filearchive/” is deleted, the copy in ”/content/tmp/” will persist !!</note>

Docu: –
Forum: Flash swf file doesn't display in multimedia content part

Author: K.Heermann (flip-flop)
CMS Version: >= 1.4x
Version: V1.0 (07.09.2010)

  • $phpwcms['allow_ext_init'] = 1;

Example template:

For a better identification and runtime optimization you must insert <!--COPY_SWF//--> into the template.

File: template/inc_cntpart/multimedia/copy_swf.tmpl

    <div class="multimedia">


File: /template/inc_script/frontend_init/cp_trig_multimedia_copy_swf.php


// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 * *****************************************************************************
 * SWF file: the files in the directory /filearchive/ are protected by an htaccess file
 * If you want to give up this protection, this script can be used.
 * Copy SWF file from folder /filearchive/ into the folder /content/tmp/
 * V1.0  07.09.10 K.Heermann
 * ---- Template ------------------------------------------
 * Please insert <!--COPY_SWF//--> into your multimedia
 * template for a better identification of this CP.
 * folder: /template/inc_cntpart/multimedia/
    <div class="multimedia">
 * *****************************************************************************
function CP_MULTIMEDIA_COPY_SWF($text, & $data) {
    // CP type multimedia = 9
    if( $data['acontent_type'] == 9 AND strpos($text, '<!--COPY_SWF//-->') ) {
        // Is there any swf file in source?
        if (preg_match('@value="'.PHPWCMS_FILES.'(.*?)\.swf"@i', $text, $filename)) {
            // Yes it is and we have catched the filename
            if ($filename[1] ) {
            $source = PHPWCMS_FILES.$filename[1].'.swf';    // Source dir and filename
            $target = 'content/tmp/'.$filename[1].'.swf';    // Destination dir and filename
            $error = false;
                // file already exists in destination dir?
                if (!is_file ($target)) {
                    // No, please copy into
                    if (!copy($source, $target)) {
                        $error = true;
                // Change folder in html source
                $text = preg_replace('@="'.$source.'"@i','="'.$target.'"',$text);
        if ($error)
            str_replace('<!--COPY_SWF//-->','Error while copying the file!!<br>',$text);
    return $text;
} // ---- END function
english/phpwcms_replacer_rts/frontend_init/cp_trigger/multimedia-copy-swf-file.txt · Last modified: 2018/06/03 18:09 (external edit) Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0