SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    la
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Random Pic php script

    I've been usign the following php script for random sigs and avatars in vBulletin. It works fine for the defined image types, but I'd like to include small flash movies for avatars etc. The script seems to work fine outside of the forums, but doesn't parse the .swf in posts. Anyone have any idea's? Below is the script, notice that I've added the following line.
    PHP Code:
    $extList['swf'] = 'application/x-shockwave-flash'
    Here's the full script.

    PHP Code:
    <?

    // set image directory if '.' = image dir


            
    $folder '.';




       
    $extList = array();
            
    $extList['gif'] = 'image/gif';
            
    $extList['jpg'] = 'image/jpeg';
            
    $extList['jpeg'] = 'image/jpeg';
            
    $extList['png'] = 'image/png';
            
    $extList['swf'] = 'application/x-shockwave-flash';   




    // --------------------- END CONFIGURATION -----------------------

    $img null;

    if (
    substr($folder,-1) != '/') {        $folder $folder.'/'; }

    if (isset(
    $_GET['img'])) {
            
    $imageInfo pathinfo($_GET['img']);
            if (isset( 
    $extListstrtolower$imageInfo['extension'] ) ] ) &&
            
    file_exists$folder.$imageInfo['basename'] )) {
                    
    $img $folder.$imageInfo['basename'];
            }
    } else {
            
    $fileList = array();
            
    $handle opendir($folder);
            while ( 
    false !== ( $file readdir($handle) ) ) {
                    
    $file_info pathinfo($file);
                    if (
                        isset( 
    $extListstrtolower$file_info['extension'] ) ] )
                    ) {
                            
    $fileList[] = $file;
                    }
            }
            
    closedir($handle);

            
    // If we have at least 1 image
            
    if (count($fileList) > 0) {
                    
    $imageNumber time() % count($fileList);
                    
    $img $folder.$fileList[$imageNumber];
            }
    }

    if (
    $img!=null) {
            
    $imageInfo pathinfo($img);
            
    $contentType 'Content-type: '.$extList$imageInfo['extension'] ];
            
    header ($contentType);
            
    readfile($img);
    } else {
            if ( 
    function_exists('imagecreate') ) {
                    
    header ("Content-type: image/png");
                    
    $im = @imagecreate (100100)
                        or die (
    "Cannot initialize new GD image stream");
                    
    $background_color imagecolorallocate ($im255255255);
                    
    $text_color imagecolorallocate ($im0,0,0);
                    
    imagestring ($im255,  "You broke it!"$text_color);
                    
    imagepng ($im);
                    
    imagedestroy($im);
            }
    }

    ?>
    Any help would be greatly appreciated. Thanks in advance.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Boston
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi


    I am sorry to say, you can not do that with embeded objects! The object must be called from the local disk as a IO type file handle. I had spoken to a few Macromedia developers at the last Perl workshop I was teaching at about this and was told that maybe in a future XHTML version more options will be allowed, but for now it can not be done!

    I spent 3 days trying to do this a few years ago, I did get it to work using IE, but it would pop a security warning. It still does that for IE 6!

    J!

  3. #3
    SitePoint Member
    Join Date
    Nov 2004
    Location
    la
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I got the script to call random .swf movies. If I place the script named index.php into a directory with .swf files, it will call them randomly with no problem. The problem I'm having is making vBulletin call them for sigs or avatars.(actually user titles.) I think it's more a limitation of vBuletin than the script. VBB has no problem parsing a directory (/titles/username) or a php file /titles/username/index.php) for random images. However, it won't work when trying to call the .swf movies. In places of the swf it leaves a broken image box, but no red x. I guess this would be more of a vbulletin.org question. Thanks for your reply though.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Boston
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I guess you are not understanding me!'


    You can not write HTTP header tags into a embedded object, it will not work! It not a VB issue. Just make a <if condition=""> in your template and link to the flash movie!

    You can not do this...

    header ( 'Content-type: application/x-shockwave-flash' );

    readfile($img);

    into a flash object!


    J!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •