Replacing an Image.

Description:   This WebSmart example looks for an image and if that image is not found replaces it with a new image.

  1. Start WebSmart go to File->New... In the new window select PHP Templates-> iSeries SQL-> A Simple Page.tpl"

  2. Go to Attributes->Files, type in MU_ITMF for the file and XL_WEBDEMO for the file library. Click OK, and OK again.

  3. In the PHP- Source Code tab after

    global $wsnum;

    add:
     $b,$a, $image 
                          
    So it looks like:
    			global $wsnum, $b,$a, $image ;
    						


  4. Replace:
                          function generic()
                          	{
    wrtseg('MainSeg'); }
    With the following:
                          function generic()
    		{
    	
    	// Make all global variables available here
    	foreach($GLOBALS as $arraykey => $arrayvalue) 
    	{
    		if ($arraykey[0]!='_' && image != 'GLOBALS')
    			global $$arraykey;
    	}
    	
    	
    	$a = "http://esdi.excelsystems.com/websmart/Images/websmart.gif"; 
    	$b= "http://esdi.excelsystems.com/websmart/Images/websmart-sample-app-255x96.gif";
    	$image;
    	if (file_exists($a)){
    	$image=$a;		
    		
    	}
    	else{ 
    		 $image=$b;
    
    	}
    
    	
    	wrtseg('MainSeg');
    	
    	}
    
                          
  5. In the MainSeg tab, immediately after the
                         < div id="contents">
                        
    Add:

                        <?php
                         	
    					
    		echo "< img src=\"" . $image . "\">";
                         
                            
                            ?>
                            

    So it looks like:
                        < div id="contents"> 
                            
                            
                            <?php
                         	
    					
    		echo "< img src=\"" . $image . "\">";
                         
                            
                            ?>
                            
                            
                         < /div>
    </div> </div>
                          

Program Definition:   replaceimage.phw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.