Search code examples
phpflashswfobjectdocument-root

Display SWF object out of the doc root


How can I display a SWF file that is out of the document root using SWFObject? I can use PHP if needed. The reason why the SWF files are outside of the doc root is because the SWFs should only be accessible by paying customers and I don't wan't people accessing them for free thru the URL.


Solution

  • Couple of options...

    Option 1: Create a symbolic link to the SWF file under the document root

    For example

    ln -s /path/to/file.swf /public/path/to/link.swf

    This will not prevent public access to the link.

    Option 2: Create a PHP file under the document root to marshal the file using readfile() or similar. You may have trouble trying to use flashvars or any other request parameters as these generally rely on an HTTP request. Then again, it might just work. Test it and report back :)

    The URL you would pass to SWFObject would be the PHP file.

    For example

    <?php
    // marshal-swf.php
    
    // do what you need to do to approve the request
    
    readfile('/path/to/file.swf');
    

    And in your JavaScript

    swfobject.embedSWF("marshal-swf.php", /* other options */);