Jump to content

How to read images from 2 or more folders.


Recommended Posts

How to read images from 2 or more folders:

I have the folders:
img/p/a with 1000 files
img/p/b in 1000 files
img/p/c with 900 files

links.php the file I am modifying the line:

public function getImageLink($name, $ids, $type = null)
   {
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_A_.$ids.($type ? '-'.$type : '').'.jpg');
   } 



change:

public function getImageLink($name, $ids, $type = null)
   {
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_A_.$ids.($type ? '-'.$type : '').'.jpg');
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_B_.$ids.($type ? '-'.$type : '').'.jpg');
return ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_C_.$ids.($type ? '-'.$type : '').'.jpg');
   } 



It does not work, I only read the images of the first directory. Missing is any OR or AND, but not how, agradeze your help and there are many waiting for this change because my server does not support more than 1000 files per folder.

Link to comment
Share on other sites

I would bet it's the "return" keyword. That usually signals exiting the function at that point, so it may never even check the other folders. Try evaluating the conditions and storing the result in a local variable then only return the local variable. Maybe something like:

public function getImageLink($name, $ids, $type = null) {
   $link = ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_A_.$ids.($type ? '-'.$type : '').'.jpg');
   $link = ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_B_.$ids.($type ? '-'.$type : '').'.jpg');
   $link = ($this->allow == 1) ? (__PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_PROD_DIR_C_.$ids.($type ? '-'.$type : '').'.jpg');

   return $link;
} 



This may not work exactly as written, because I don't have any place to test it right now; but it should give you a general idea of the concept. I'm not sure what $this->allow represents.

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...