Jump to content

Cant figure this out


holladb

Recommended Posts

Hey i cant figure this out.

 

I just got a new debian server for our client using PHP5 and the GD Library.

 

My problem is that I can't figure out why one of the tables isn't pulling from the database.

 

http://www.idealclothing.net everything is fine and the images work.

 

On our offline new debian server everything works fine except the images.

 

We're using a custom templating system. The code doesn't seem to be transfering over the "src" on the new server.

 

Here is the code where it's supposed to be pulling.

 

<?
require_once 'inc/config.inc.php';
$id = intval($id);
$db->setTable($GLOBALS['t_items']);
$irow = $db->get("id='$id'");
//echo $id; exit;
//echo "<pre>"; print_r($irow); exit;

$no_list = $db->get("id='".$irow['categories_id']."'", 'is_no_list', $GLOBALS['t_categories']);

$tpl->loadTemplatefile('contentb');
$db->setTable($GLOBALS['t_brands']);
$rows = $db->select("categories_id='".$irow['categories_id']."' and name!=''", 'name');
$alias = $db->get('id='.intval($irow['categories_id']), 'alias', $GLOBALS['t_categories']);
if (isset($rows)&&is_array($rows)) {
    if ($no_list != 1 && $irow['brandid'] != '') {
        array_unshift($rows, array('category_alias'=> $alias, 'name' => 'All'));
    }
    foreach ($rows as $row) {
        $row[name] = str_replace(' ', ' ', $row[name]);
        if ($irow['brandid'] == $row['id']) {
            $tpl->setCurrentBlock('brands_active_link');
            $tpl->setVariable(array(
                'category_alias'=> $alias,
                'alias'         => $row['alias'],
                'name'          => $row['name'],
                'is_new'        => ($row['is_new'])?'':null,
                'is_clearance'  => ($row['is_clearance'])?'':null
            ));
        } else {
            $tpl->setCurrentBlock('brands_inactive_row');
            $tpl->setVariable(array(
                'category_alias'=> $alias,
                'alias'         => $row['alias'],
                'name'          => $row['name'],
                'is_new'        => ($row['is_new'])?'':null,
                'is_clearance'  => ($row['is_clearance'])?'':null
            ));
        }
        $tpl->parseCurrentBlock();
        $tpl->setCurrentBlock('brands');
        $tpl->parseCurrentBlock();
    }
}
$contentb = $tpl->get();

$row = $irow;
$multiple_images = false;
$tpl->loadTemplatefile('item_new');
$file_info = getImage('items', $row['image']);

if ($file_info['src'] != '') {
    $first_src = $file_info['src'];
    $row['src'] = $file_info['src'];
    $row['width'] = $file_info['width'];
    $row['height'] = $file_info['height'];
}
//echo "<pre>"; print_r($row); exit;

$row['is_new'] = ($row['is_new'])?'':null;
$row['is_sale'] = (($row['is_sale']) ? (($row['original_price'] > 0) ? ('(Original Price: &#36;'.$row['original_price'].')') : "") : null);
$row['description'] = nl2br($row['description']);
$row['from_date'] = ($row['from_date'] == '' || $row['from_date'] == '0000-00-00')?null:dateFormat($row['from_date']);
$row['to_date'] = ($row['to_date'] == '' || $row['to_date'] == '0000-00-00')?null:dateFormat($row['to_date']);

$file_info = getImage('items', $row['second']);
if ($file_info['src']) {
  $tpl->setCurrentBlock('second_image');
  $multiple_images = true;

  $im = array();
  $im['src'] = $file_info['src'];
  $im['id'] = $id;

  if((int)$_GET['image'] == 2)
  {
    $row['src'] = $file_info['src'];
  }

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

$file_info = getImage('items', $row['third']);
if ($file_info['src']) {
  $tpl->setCurrentBlock('third_image');
  $multiple_images = true;

  $im = array();
  $im['src'] = $file_info['src'];
  $im['id'] = $id;

  if((int)$_GET['image'] == 3)
  {
    $row['src'] = $file_info['src'];
  }

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

$file_info = getImage('items', $row['fourth']);
if ($file_info['src']) {
  $tpl->setCurrentBlock('fourth_image');
  $multiple_images = true;

  $im = array();
  $im['src'] = $file_info['src'];
  $im['id'] = $id;

  if((int)$_GET['image'] == 4)
  {
    $row['src'] = $file_info['src'];
  }

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

$file_info = getImage('items', $row['fifth']);
if ($file_info['src']) {
  $tpl->setCurrentBlock('fifth_image');
  $multiple_images = true;

  $im = array();
  $im['src'] = $file_info['src'];
  $im['id'] = $id;

  if((int)$_GET['image'] == 5)
  {
    $row['src'] = $file_info['src'];
  }

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

$file_info = getImage('items', $row['swatch']);
if ($file_info['src']) {
  $tpl->setCurrentBlock('swatch_image');

  $im = array();
  $im['src'] = $file_info['src'];

  if($row['swatch_text'])
  {
$im['swatch_text_message'] = nl2br($row['swatch_text']);
  }
  else
  {
$im['swatch_text_message'] = 'Color Swatch';
  }

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

// Only display the first thumbnail if there are others...
if ($row['src'] && $multiple_images) {
  $tpl->setCurrentBlock('first_image');

  $im = array();
  $im['src'] = $first_src;
  $im['id'] = $id;

  $tpl->setVariable($im);
  $tpl->parseCurrentBlock();
}

for ($i=1;$i<=5;$i++) {
    $db->setTable($GLOBALS['t_items_params']);
    $prows = $db->select("items_id='".$row['id']."' AND params_id='$i'", 'id');
//    sort($prows);
//    echo "<pre>"; print_r($prows); 
    $options = '';
    $list = '';
    if (isset($prows) && is_array($prows)) {

        foreach ($prows as $prow) {
            $options .= '<option value="'.$prow[name].'">'.$prow[name];
            if ($list != '') $list .= ',';
            $list .= $prow[name];
        }
    }
    $row['param'.$i.'_name'] = $ITEMS_PARAMS[$i];
    $row['param'.$i.'_options'] = $options;
}

$brand_data = $db->get("id='".intval($row['brandid'])."'", '', $GLOBALS['t_brands']);
$stext = $db->get("id='".$brand_data['size_charts_id']."'", 'text', $GLOBALS['t_size_charts']);

if ($stext == '') {
    unset($row['brandid']);
}

$tpl->setVariable($row);
$_SESSION['ideal_back'] = 'item.php?id='.$id;
$item_id = $id;
parseGlobal('global', $contentb);
$db->disconnect();
$tpl->show();
?>

Link to comment
Share on other sites

Have you echoed out the variable so that you know if or what it contains? Is the data present in the database? If the images are generated by GD, post the code responsible for outputting the images. If you browse directly to a URL for an image does the image display?

Link to comment
Share on other sites

the code generating the images is fine. it does that. tested and works.

 

As far as it holding the data, yes it does. The function responsible for pulling the image from the database however does not work.

 

    function getImage($table, $value) {
        if ($value == '') {
            return array();
        }
        eval('$path = '.strtoupper($table.'_path').';');
        $path = FILES_PATH.$path;
        $file_name = $path.$value;
        if (file_exists($file_name)) {
            $file_info = getimagesize($file_name);
            return array(
                'src'       => '/'.$file_name,
                'width'     => $file_info[0],
                'height'    => $file_info[1],
            );
        }
        return array();
    }

 

I did a little test just changing the above to something standard like "/files.jpg"; and it outputted src=/

It looks like some where there is an error where it's only allow the variable to handle 1 character.

Link to comment
Share on other sites

[code]look at yer code closely
[code]eval('$path = '.strtoupper($table.'_path').';');
        $path = FILES_PATH.$path;
        $file_name = $path.$value;
        if (file_exists($file_name)) {

there is no need for using eval here.

 

but these 3 lines, convert a directory name to full uppercase.

under windows, this dusn really matter.

under linux, it matters

 

so when it fails to find the proper path, it dusn set anything.

 

as for the eval in the code, this does the same thing :)

[/code]'$path = FILES_PATH . strtoupper($table.'_path');

        $file_name = $path.$value;

        if (file_exists($file_name)) {[/code]

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.