vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Image displaying from database (https://vborg.vbsupport.ru/showthread.php?t=228409)

Mythotical 11-20-2009 12:04 AM

Image displaying from database
 
I came up with my own way to pull images but the thing about is that it won't pull the image on vB4.0, here is the template and file.

Template:
HTML Code:

<img src="download.php?catimg={vb:var cid}" height="50">
Template with pulling image data through different file other than download.php:
HTML Code:

<img src="cat.php?img={vb:var cid}" height="50">
Keep in mind the var $cid is pulled in the download.php file while the image pull is a separate file but right now I want to attempt to combine the files into one.

File:
PHP Code:

if ($vbulletin->options['bfc_download_active']){
$img $_REQUEST['img'];

$result $db->query_read("SELECT cat_icon,cat_type FROM download_cats WHERE catid=" $img); 
   while (
$row $db->fetch_array($result) ) { 
    
$sid $row['cid'];
    
$type $row['cat_type'];
    
$encodeddata $row['cat_icon']; 
    }
$data = @mysql_RESULT($result,0,'cat_icon');
$type = @mysql_RESULT($result,0,'cat_type');

header"Content-type: $type"); 
echo 
$data;


Code that is pulling the data for the $cid variable:
PHP Code:

$sql $vbulletin->db->query_read("SELECT * FROM `" TABLE_PREFIX "download_cats` WHERE cat_active = '1'");

$total $vbulletin->db->num_rows($sql);
$i=0;
$perrow $total-2;

while (
$row $db->fetch_array($sql))
{
    
$cid $row['catid'];
    
$cat $row['catitle'];
    
$description $row['cat_description']; 
    
$caticon $row['cat_icon'];
        
$i++;

    if (
$total !== 0)
    {
  
    if (
$total $perrow){
            
$catc '</td>';
        
$perrow $perrow+2;
    } else {
$perrow $perrow-2;
    
$catc '</td></tr><tr>';
    }
        
$catb vB_Template::create('bfc_download_cat_bit');
            
$catb->register('cat_bit'$cat_bit);
            
$cat_bit .= $catb->render();  
    } 

Any help much appreciated.

Thanks
Steve M

cellarius 11-20-2009 09:55 AM

Where do you register $cid for use in the template in the second chunk of code?

Mythotical 11-20-2009 05:05 PM

PHP Code:

while ($row $db->fetch_array($sql))
{
    
$cid $row['catid']; 

Is that what you mean by registered? Or are you talking about cleaned?

cellarius 11-20-2009 06:10 PM

You need to register variables to make them available in templates:
https://vborg.vbsupport.ru/showthread.php?t=228078

I thought you knew all that, since you're already doing it:
PHP Code:

$catb vB_Template::create('bfc_download_cat_bit');
            
$catb->register('cat_bit'$cat_bit);
            
$cat_bit .= $catb->render(); 

You need to do the same as in the second line for $catb for $cid.

Mythotical 11-20-2009 06:21 PM

$cid is not a template or do all variables you use no matter if they are a template or not need to be registered?

I knew about templates but was unaware of having to do it for data variables such as $cid.

cellarius 11-20-2009 06:29 PM

bfc_download_cat_bit is the template. You create it by calling the vB_Template:create method, and then you need to register every variable you want to use inside that template, no matter what's saved inside that variable. It can contain a rendered template, or it can contain just a simple boolean false or true. That does not matter, you need to register it to be able to use it. Then, in the next step, you render the template.

Mythotical 11-20-2009 06:30 PM

Ok I can't figure out why this:
HTML Code:

</td> </td></tr><tr>
Is displaying above my results when it should only use those if its starting a new row and ending another.

DavidsMods 11-20-2009 10:32 PM

Just a quick note on security :)

PHP Code:

$img $_REQUEST['img']; 

Should be cleaned as you are using it here:
PHP Code:

$result $db->query_read("SELECT cat_icon,cat_type FROM download_cats WHERE catid=" $img); 


Mythotical 11-20-2009 10:36 PM

Thanks for pointing that out, I was actually starting to think I needed to clean it.


All times are GMT. The time now is 06:07 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01918 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_html_printable
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete