My task..

was to switch a block's content image/swf in particular pages. Usually the pages could be a node or taxonomy term. So i had written a block snippets to check for image/swf file's existence using file_exists where i have saved such images in a particular logic. What i was trying to do, is to get the node id and look for an image or swf in files folder.

Now about the problem, i was using Clean URL in my drupal 5.7 installation. The following code did not worked when the Clean URL is activated. But worked fine when Clean URL was disabled. by debugging ( echo :( ) i saw that when clean url was activated file_exists() always returned false.

Though clean URL or query URL is not a major issue in my required work. But i prefer Clean URL. So, can anyone refer the actual cause of the problem or where am i wrong??

Thanks in advance.


<?php

  $image_path = base_path() . "files/images/";
  $dflt_image = "top_image_1.jpg";
  $image_prfx = "top_image_";
  $swf_prfx = "top_swf_";
  
  
  $id = 1;
  if( arg(0) == 'node' and (int)arg(1) != 0 ) 
		$id = arg(1); /* Getting Node Information */	
  
   
  // Looking for image
  if( file_exists($image_path . $image_prfx . "$id.jpg") and $id != 1) {
	echo "<img src='" . $image_path . $image_prfx . "$id.jpg' />";
  }  
  else if( file_exists($image_path . $swf_prfx . "$id.swf") ) {
	// Looking for swf
	echo '
	 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 	
				codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" 				width="970" height="200">							
			<param name="movie" value="';
	echo $image_path . $swf_prfx . "$id.swf"; 
	echo '" />
			<param name="quality" value="high" />							
			<param name="play" value="true" />							
			<param name="loop" value="true" />							
			<embed src="';
	echo $image_path . $swf_prfx . "$id.swf"; 
	echo '"  								
			quality="high" width="970"								
			height="200" name="movie" align="" 									
			type="application/x-shockwave-flash"								
			plug inspage="http://www.macromedia.com/go/getflashplayer"> 							
			</object>';
			
  }else {
	echo "<img src='" . $image_path . $image_prfx . "1.jpg' />";
  }
?>

Comments

lurkerfilms’s picture

I am be totally wrong here but doesn't base_path() return the path portion of your website's URL (i.e. the logical path you install drupal into) and doesn't file_exists() check for file system files or full urls?

So the code as is... would always look in the wrong place...

e.g. (assuming your installation is at drupal)
url = http://www.yoursite.com/drupal/files/images/pic.jpg
base_path() = /drupal/
physical file = /users/yoursite/html_public/drupal/files/images/pic.jpg
relative path = files/images/pic.jpg
file_exists("/drupal/files/images.pic.jpg") = false

Won't file_exists always return false since /drupal/files/images/pic.jpg does not exist at the absolute path in the file system?

Seems you are mixing file system checks with url checks.

Andrew Migliore
Lurker Films Inc.
http://www.lurkerfilms.com