Jump to content

php 4 to php5 help


javivilchis

Recommended Posts

Hello all,

I need help with merging php 4 to 5, i'm getting the following errors but I don't see and don't know if is the syntax that is wrong or if there is a new way of calling the variables, Please help.

 

Notice: Undefined variable: path in F:\hyacinthvases\imagegallery2\index.php on line 143

the code below starts on line 143

$path = adjustPath($path);
  if(!$page)
    $page = 0;


  if(!$g_cols)
    $g_cols = 4;
  if(!$g_rows)
    $g_rows = 1;
  if(!$g_title)
    $g_title = "Image Gallery";
  if(!$g_twidth)
    $g_twidth = 100;

  $files = array();
  $isDir = array("." => false);
  @readFiles($path, $files, $isDir);

 

Notice: Undefined variable: page in F:\hyacinthvases\imagegallery2\index.php on line 144

Link to comment
https://forums.phpfreaks.com/topic/163257-php-4-to-php5-help/
Share on other sites

It just means that you are using $path without it having been defined somewhere before.  Perhaps something like this would fix it:

 

<?php
$path = (isset($path)) ? $path : '';

$path = adjustPath($path);
  if(!$page)
    $page = 0;


  if(!$g_cols)
    $g_cols = 4;
  if(!$g_rows)
    $g_rows = 1;
  if(!$g_title)
    $g_title = "Image Gallery";
  if(!$g_twidth)
    $g_twidth = 100;

  $files = array();
  $isDir = array("." => false);
  @readFiles($path, $files, $isDir);

Link to comment
https://forums.phpfreaks.com/topic/163257-php-4-to-php5-help/#findComment-861326
Share on other sites

sorry fly for not placing the whole script, but I am declaring the path in a func.php file whic I called in on line: 141

 

<?php
  
  // in case register global is off
  foreach($HTTP_GET_VARS as $key => $val) {
     $$key = $val;
     global $$key;
  }

  global $files, $isDir, $g_twidth, $g_cols, $g_rows, $g_title, $g_desc, $g_dispFn, $g_sortByFn, $g_folderImg, $g_showInPopup, $g_popupWidth, $g_popupHeight;

  include("func.php");
  $path = adjustPath($path);
  if(!$page)
    $page = 0;


  if(!$g_cols)
    $g_cols = 4;
  if(!$g_rows)
    $g_rows = 1;
  if(!$g_title)
    $g_title = "Image Gallery";
  if(!$g_twidth)
    $g_twidth = 100;

  $files = array();
  $isDir = array("." => false);
  @readFiles($path, $files, $isDir);
?>

func.php file

<?
function showImg($aPath, $aFn, $aIdx, $aThisPage, $aSubDir="")
{
  global $g_twidth, $g_dispFn, $g_thumb_worh, $g_showInPopup, $g_popupWidth, $g_popupHeight, $g_shrinkPopup;

  $fullpath = $aPath.$aFn;

  // find the width and height of the thumbnail
  $imgsize = GetImageSize($fullpath);
  if($g_thumb_worh == 'w') {
    $twidth = $g_twidth;
    $theight = $imgsize[1] / ($imgsize[0]/$twidth);
  } else {
    $theight = $g_twidth;
    $twidth = $imgsize[0] / ($imgsize[1]/$theight);
  }

  // generate the html
  echo "<td>";
  if($aSubDir != "") {
    echo "<center><a href=\"$PHP_SELF?path=$aPath\"><img border=\"0\" width=\"$twidth\" height=\"$theight\" src=\"genthumbs.php?image=$fullpath&w=$twidth\"></img></a></center>";
  } else {
    // need scrollbar?
    $sb = "yes";
    if($g_showInPopup == 'check') {
      $w = $g_popupWidth;
      $h = $g_popupHeight;
      if($g_shrinkPopup == 'check') {
        $picsize = GetImageSize($aPath.$aFn);
        if($picsize[0]+10 < $w && $picsize[1]+10 < $h) {
          $w = $picsize[0]+10;
          $h = $picsize[1]+10;
          $sb = "no";
        }

      }
      echo "<center><a href=# onclick=\"javascript:window.open('$aPath$aFn', '_blank', 'width=$w, height=$h, scrollbars=$sb');return false\"><img border=\"0\" width=\"$twidth\" height=\"$theight\" src=\"genthumbs.php?image=$fullpath&w=$twidth\"></img></a></center>";
      
    } else
      echo "<center><a href=\"$PHP_SELF?path=$aPath&page=$aThisPage&img=$aFn&idx=$aIdx\"><img border=\"0\" width=\"$twidth\" height=\"$theight\" src=\"genthumbs.php?image=$fullpath&w=$twidth\"></img></a></center>";
  }

  // display filename?
  if($g_dispFn) {
    echo "<br><center>";
    if($aSubDir == "") {
      $l = strlen($aFn) - 4;
      echo substr($aFn, 0, $l);
    } else {
      echo $aSubDir."[dir]";
    }
    echo "</center>";
  }
  echo "</td>";

}

/*
* show the image in real size
*/
function showBigImg($aPath, $aIdx)
{
  global $files, $isDir; 

  echo "<center>";
  echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";

  if($isDir[$files[$aIdx]]) {
    showDir($aPath, $files[$aIdx]);
  } else {
    // generate the html

    echo "<td>";
    echo "<center><img border=\"0\" src=\"".$aPath.$files[$aIdx]."\"></img></center>";
    echo "</td>";

    echo "</table>";
    echo "</center>";
  }
}

/*
* get the filename of the first image from a folder
*/
function getFirstImgFn($aPath, $aExt)
{
  $dir_handle = @opendir($aPath) or die("Unable to open $aPath");

  while($file = readdir($dir_handle)) {
    $fullpath = $aPath.$file;

    if(is_dir($fullpath) == false) {
      $ext = substr($file, -4);
      if(strtolower($ext) == $aExt) {
        return $file;
      }
    }
  }
  /*
   * return empty if no img exists.
   */
  return "";
}

/*
* get the filename of a random image from a folder
*/
function getRandomImgFn($aPath, $aExt)
{
  $dir_handle = @opendir($aPath) or die("Unable to open $aPath");

  $imgfiles = array();
  while($file = readdir($dir_handle)) {
    $fullpath = $aPath.$file;

    if(is_dir($fullpath) == false) {
      $ext = substr($file, -4);
      if(strtolower($ext) == $aExt) {
        $imgfiles[] = $file;
      }
    }
  }
  
  $num = count($imgfiles);
  if($num <= 0) {
    /*
     * return empty if no img exists.
     */
    return "";
  }

  /* 
   * randomly pick one
   */
  $idx = rand(0, $num-1);
  return $imgfiles[$idx];  
  
}

/*
* show the thumb / image of a folder
*/
function showDir($aPath, $aFn)
{
  global $g_showFirstThumb, $g_folderImg;
  $fullpath = $aPath.$aFn."/";
  
  // 3 --> first jpg image, 4 --> random jpg image
  if($g_folderImg == '3' || $g_folderImg == '4') {
     $fn = "";
     if($g_folderImg == '3')
       $fn = getFirstImgFn($fullpath, '.jpg');
     else
       $fn = getRandomImgFn($fullpath, '.jpg');	

     if($fn != "") {
       showImg($fullpath, $fn, "0", "0", $aFn);
       return;
     }
  }

  echo "<td>";
  $done = false;
  // 2 --> first gif image
  if($g_folderImg == '2') {
    $fn = getFirstImgFn($fullpath, '.gif');
    if($fn != "") {
      $imgsize = GetImageSize($fullpath.$fn);
      echo "<center><a href=\"$PHP_SELF?path=$fullpath\"><img border=\"0\" width=\"$imgsize[0]\" height=\"$imgsize[1]\" src=\"$fullpath$fn\"></img></a></center>";
      $done = true;
    }
  }
  
  // default is folder.gif
  if($done == false) {
    $imgsize = GetImageSize("folder.gif");
    echo "<center><a href=\"$PHP_SELF?path=$fullpath\"><img border=\"0\" width=\"$imgsize[0]\" height=\"$imgsize[1]\" src=\"folder.gif\"></img></a></center>";
  }
  
  echo "<br><center>$aFn</center>";
  echo "</td>";

}

/*
* show 1 row of thumbs
*/
function showImgRow($aPath, $aFiles, $aIsDir, $aThisPage, $aStart, $aEnd)
{
  echo "<tr>";
  for($i=$aStart; $i<$aEnd; $i++) {
    if($aIsDir["_".$aFiles[$i]]) {
      showDir($aPath, $aFiles[$i]);
    } else {
      showImg($aPath, $aFiles[$i], $i, $aThisPage);
    }
  }
  echo "</tr>";
}

/*
* show the whole table of thumbs
*/
function showImgTable($aPath, $aFiles, $aIsDir, $aThisPage,
$aNumCols, $aNumRows)
{
  global $g_spacing;
  
  $numPerPage = $aNumRows * $aNumCols;
  $totalFiles = count($aFiles);
  $start = $aThisPage * $numPerPage;
  $end = $start + $numPerPage;
  $end = min($end, $totalFiles);

  echo "<center>";
  echo "<table border=\"0\" cellspacing=\"$g_spacing\" cellpadding=\"0\">";

  while($start < $end) {
    $e = min($start + $aNumCols, $end);
    showImgRow($aPath, $aFiles, $aIsDir, $aThisPage, $start, $e);
    $start += $aNumCols;
  }

  echo "</table>";
  echo "</center>";
}

/*
* show the links to different pages
*/
function showPageLinks($aPath, $aNumFiles, $aThisPage, $aIdx, $aNumCols, $aNumRows)
{
  global $files;
  $numPerPage = $aNumCols * $aNumRows;
  $numPages = ceil($aNumFiles / $numPerPage);

  /*
   * reverse finding '/' start from the second last char
   * since the last char must be '/'
   */
  $pdir = "";
  $plen = strlen($aPath);
  for($j=$plen-2; $j>0; $j--) {
    if($aPath[$j] == '/') {
      $pdir = substr($aPath, 0, $j+1);
      break;
    }
  }

  echo "<br><center>";
  echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";
  echo "<tr>";
  if($aIdx != "") {
    // Showing back link
    echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$aThisPage\">Back To Thumbs</a></td>";
    // show prev, next link
    if($aIdx > 0) {
      $idx = $aIdx - 1;
      echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$aThisPage&idx=$idx\"><</a></td>";
    }
    if($aIdx + 1 < count($files)) {
      $idx = $aIdx + 1;
      echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$aThisPage&idx=$idx\">></a></td>";
    }
  } else {
    // show the up link
    if($pdir != "") {
      echo "<td><a href=\"$PHP_SELF?path=$pdir\">UP</a></td>";
    }
    // show the page links
    if($numPages == 0) {
      echo "<td>No image in this folder</td>";
    } else { 
      // show only 10 pages
      $minp = 0;
      $maxp = 10;
      if($numPages > 10) {
        $minp = floor($aThisPage/10) * 10;
        $maxp = ceil(($aThisPage+1)/10) * 10;
      }
      $maxp = min($maxp, $numPages);

      echo "<td>page:</td>";

      // show the prev link
      if($minp >= 10) {
        $prevp = $minp - 1;
        echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$prevp\"><</a></td>";
      }

      // show page no(s)
      for($i=$minp; $i<$maxp; $i++) {
        $p = $i + 1;
        if($aThisPage == $i) {
          echo "<td><b>$p</b></td>";
        } else {
          echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$i\">$p</a></td>";
        }
      }

      // show the next link
      if($maxp < $numPages) {
        $nextp = $maxp;
        echo "<td><a href=\"$PHP_SELF?path=$aPath&page=$nextp\">></a></td>";
      }
    }
  }
  echo "</tr>";
  echo "</table>";
  echo "</center>";
}

function showFooter()
{
  echo "<center><font size=\"-2\"><a target=\"_blank\" href=\"http://www.flash-here.com/downloads/fhimage.html\">FhImage</a>, powered by <a target=\"_blank\" href=\"http://www.flash-here.com\">Flash-here.com</a></font></center>";

}

// case insensitive comparison
function cicmp($a, $b)
{
  return strcasecmp($a, $b);
}


/*
* read file / dir names from a directory 
*/
function readFiles($aPath, &$aFiles, &$aIsDir)
{

  global $g_sortByFn, $g_insensitive_sort;
  $confdir = "imgconfig";

  $dir_handle = @opendir($aPath) or die("Unable to open $aPath");

  while($file = readdir($dir_handle)) {
    $fullpath = $aPath.$file;

    if(is_dir($fullpath)) {
      if($file != '.' && $file != '..' && $file != $confdir) {
        $aFiles[] = $file;
        $tmparray = array("_".$file => true);
        $aIsDir = array_merge($aIsDir, $tmparray);
      }
    } else {
      $ext = substr($file, -4);
      if($file[0] != '.' && (strtolower($ext) == '.jpg')) {
        $aFiles[] = $file;
        $tmparray = array("_".$file => false);
        $aIsDir = array_merge($aIsDir, $tmparray);
      }
    }
    if($g_sortByFn == 'check') {
  if($g_insensitive_sort == 'check') {
  	usort($aFiles, "cicmp");
  } else {
        sort($aFiles);
  }
    }
  }

  closedir($dir_handle);
}

function adjustPath($aPath)
{
  $ret = $aPath;
  if(!$ret)
    $ret = "./";
  if(substr($ret, -1) != "/")
  $ret = $ret.'/';

  // reset to home, if illegal access
  if(substr($ret, 0, 1) != '.' || strstr($ret, "..")) {
    $ret= './';
  }
  
  return $ret;
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/163257-php-4-to-php5-help/#findComment-861336
Share on other sites

I guess this line of code fixed it.

<?php
$path = (isset($path)) ? $path : '';

$path = adjustPath($path);
  if(!$page)
    $page = 0;


  if(!$g_cols)
    $g_cols = 4;
  if(!$g_rows)
    $g_rows = 1;
  if(!$g_title)
    $g_title = "Image Gallery";
  if(!$g_twidth)
    $g_twidth = 100;

  $files = array();
  $isDir = array("." => false);
  @readFiles($path, $files, $isDir);

 

thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/163257-php-4-to-php5-help/#findComment-861363
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.