I have created a basic component for Joomla that allows users to list an item along with some associated images. When the page containing the gallery is viewed a strange folder is created in the root web directory in the format of Resource id #100, the number varies with each item. I have narrowed down the code that is causing this to the following. My question is can some see what I’m doing to cause this and can anyone offer alternatives to the code I’m using to read the files from a particular directory and return the information.
<p id="sl_gallery">
<?php if( is_file( JPATH_ROOT.'/components/com_eg/images/gallery/'.$this->eg->id.'/main.jpg' ) ) : ?>
<img src="<?php echo JURI::root().'/components/com_eg/images/gallery/'.$this->eg->id.'/main.jpg' ?>" alt="myimage">
<?php else: ?>
<img src="<?php echo JURI::root().'/components/com_eg/images/nolistings.gif'; ?>" alt="myimage" />
<?php endif; ?>
<?php
$TrackDir= opendir(JPATH_ROOT.'/components/com_eg/images/gallery/'.$this->eg->id.'/second/');
$count = 0;
if ( !JFolder::exists($TrackDir) ) { JFolder::create($TrackDir); }
while (($file = readdir($TrackDir)) !== false) {
if ($file == "." || $file == "..") { }
else {
?>
<img src="<?php echo JURI::root().'/components/com_eg/images/gallery/'.$this->eg->id.'/second/'.$file; ?>" alt="myimage" />
<?php
}
}
closedir($TrackDir); ?>
</p>
Change this:
…to this:
$TrackDirholds the result of a call toopendir()– this means it will either be a resource orFALSE. When you convert a resource to a string, it results inResource id #– which you did by (effectively) passing it tomkdir().I have stored the path as a string in a variable
$TrackDirPath, and passed that toJFolder::create()instead. I have also re-ordered the statements, to make sure that the directory exists before you try to open it.