Autor Zpráva
Dautfg
Profil *
Pěkný den, prosím o pomoc s přepsáním kousku kódu, kde je použita v PHP 5.3 nepodporovaná funkce ereg. Jsem trubka a podle manuálnu jsem to prostě nedal. Jedná se o SPMG galerii zatím není fix a já bych ptřeboval rozchodit tuto galerii na serveru s PHP 5.3 Původní kód je tento:
################################################################################
# Checks if the filname exists, refers to a picture associated to a thumbnail 
# and is granted the necessary access rigths

function spgm_IsPicture($strPictureFileName, $strGalleryId) {

  global $spgm_cfg;

  $strPicturePath = DIR_GAL.$strGalleryId.'/'.$strPictureFileName;
  $strThumbnailPath = DIR_GAL.$strGalleryId.'/'.PREF_THUMB.$strPictureFileName;
  if ( defined('DIR_THUMBS') ) {
    $strThumbnailPath = 
        DIR_GAL.$strGalleryId.'/'.DIR_THUMBS.PREF_THUMB.$strPictureFileName;
  }
  
  spgm_Trace(
    '<p>function spgm_IsPicture</p>'."\n"
    .'strPictureFileName: '.$strPictureFileName.'<br />'."\n"
    .'strGalleryId: '.$strGalleryId.'<br />'."\n"
    .'strPicturePath: '.$strPicturePath.'<br />'."\n"
    .'strThumbnailPath: '.$strThumbnailPath.'<br />'."\n"
  );
 
  // check filename patterns
  if ( PREF_THUMB != '' AND eregi('^'.PREF_THUMB.'*', $strPictureFileName) )
    return false;
  $validated = false;
  $extnb = count($spgm_cfg['global']['supportedExtensions']);
  for ($i=0; $i<$extnb; $i++) {
    if ( eregi($spgm_cfg['global']['supportedExtensions'][$i].'$', $strPictureFileName) ) {
      $validated = true;
      break;
    }
  }
  if (! $validated)
    return false; 
   
  // does it exist, is it a regular file and does it have the expected permissions ?
  if (! spgm_CheckPerms($strPicturePath) ) {
    return false;
  }
  
  // an associated thumbnail is required... same job again !
  if (! spgm_CheckPerms($strThumbnailPath) ) {
    spgm_Warning( $strPicturePath.': '.WARNMSG_THUMBNAIL_UNREADABLE.'<br />' );
    return false;
  }
  
  return true;
}

##############################################################################
# Checks if the directory corresponding the gallery is well-formed, exists 
# and is granted the necessary access rights
# $galid can be empty

function spgm_IsGallery($strGalleryId) {
	
  global $spgm_cfg;
  
  $strPathToPictures = DIR_GAL.$strGalleryId;
	
  spgm_Trace(
    '<p>function spgm_IsGallery</p>'."\n"
    .'strGalleryId: '.$strGalleryId.'<br />'."\n"
    .'strPathToPictures: '.$strPathToPictures.'<br />'."\n"
  );

  // searching for hazardous patterns
  if ( ereg('^/', $strGalleryId) || ereg('\.\.', $strGalleryId) || ereg('/$', $strGalleryId) ) {
    return false;
  }
 }

Předem děkuji za pomoc.
bohyn
Profil
Dautfg:
Většinou stačí jen ereg výraz zabalit do "oddělovačů" (třeba ~).
ereg('\.\.', $strGalleryId);
preg_match('~\.\.~', $strGalleryId); // case sensitive
preg_match('~\.\.~i', $strGalleryId); // case insensitive

Pokud něco přestane fungovat tak pošli konkrétní dotaz.
Dautfg
Profil *
bohyn:Díky to jsem udělal, vyhazuje to už jen chybu :Warning: preg_match() [function.preg-match]: No ending delimiter '.' found in C:\wamp\www\mce\galerie\spgm.php on line 410
je to tento řádek když to zkusím nějak"obalit" háže to parse error
    if ( preg_match($spgm_cfg['global']['supportedExtensions'][$i].'$', $strPictureFileName) ) {
bohyn
Profil
Dautfg:
Musíš přídat ty oddělovače. A v původním kódu bylo eregi tak za ukončovací ~ přidej ještě i (tedy ~i).
if ( preg_match('~'.$spgm_cfg['global']['supportedExtensions'][$i].'$~i', $strPictureFileName) ) {
Dautfg
Profil *
Děkuji ó mocný :-) Vše funguje perfektně.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0