Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2007, 06:00 PM
AutomatikStudio's Avatar
AutomatikStudio AutomatikStudio is offline
 
Join Date: Dec 2003
Posts: 229
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How would I show avatars?

I'm tying in to vB's user system for a site I'm working on and I'd like to display user avatars throughout the site on lots of non-vb pages. I'm having trouble getting the images to display though.

Here's the query I'm making in my avatar.php file that should display a user avatar:

PHP Code:
$sql mysql_query("SELECT filedata, dateline, filename
            FROM vb_customavatar
            WHERE userid = '1'"
);

    
$row=mysql_fetch_array($sql);

    
header("Content-Length: ".strlen($row[filedata]));
    
header('Content-transfer-encoding: binary');
    
header("Content-Disposition: inline; filename=\"".$row['filename']."\";");
    
header("Content-Type: image/jpeg");
    echo 
$row['filedata']; 
The query works fine, but it's just plain not showing the image.

Am I missing something?
Reply With Quote
  #2  
Old 01-16-2007, 07:13 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Note that the userid is numeric, you don't need the quotes (it should work with the quotes, but you are making MySQL do an extra conversion for each row.)

Try the following code, I haven't tried but it should work.

PHP Code:
$sql mysql_query("SELECT filedata, dateline, filename
            FROM vb_customavatar
            WHERE userid = 1"
); 

$row=mysql_fetch_array($sql); 

header('Cache-control: max-age=31536000');
header('Expires: ' gmdate('D, d M Y H:i:s', (TIMENOW 31536000)) . ' GMT');
header('Content-disposition: inline; filename=' $row['filename']);
header('Content-transfer-encoding: binary');
header('Content-Length: ' strlen($row['filedata']));
header('Last-Modified: ' gmdate('D, d M Y H:i:s'$row['dateline']) . ' GMT');
$extension trim(substr(strrchr(strtolower($row['filename']), '.'), 1));
if (
$extension == 'jpg' OR $extension == 'jpeg')
    
header('Content-type: image/jpeg');
else if (
$extension == 'png')
    
header('Content-type: image/png');
else
    
header('Content-type: image/gif');

echo 
$row['filedata']; 
Reply With Quote
  #3  
Old 01-16-2007, 07:21 PM
AutomatikStudio's Avatar
AutomatikStudio AutomatikStudio is offline
 
Join Date: Dec 2003
Posts: 229
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still no go. I really have no idea why. Maybe I need some tips on debugging this? I've got error reporting set to E_ALL and it's not giving me anything related to this.
Reply With Quote
  #4  
Old 01-16-2007, 07:51 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just tried it, and it works. You can see it working here: http://www.nuhit.com/test/getavatar.php?userid=86

Here is my full code: (you would need to change the location of your forums in the config_filename variable).

PHP Code:

$config_filename 
dirname(__FILE__) . "/../forums/includes/config.php";

require_once 
$config_filename;
define'TABLE_PREFIX'$config['Database']['tableprefix'] );

$userid $_REQUEST['userid'];

$conn mysql_connect$config['MasterServer']['servername'], $config['MasterServer']['username'], $config['MasterServer']['password'] );
if (!
$conn)
    die (
"Could not connect to server.");

if (!
mysql_select_db$config['Database']['dbname'], $conn ))
    die (
"Database not found.");

$sql "SELECT filedata, dateline, filename 
            FROM " 
TABLE_PREFIX "customavatar
            WHERE userid = 
$userid";
$results mysql_query($sql$conn); 
if (!
$results)
    die (
"Error running query.");

$row=mysql_fetch_array($results); 

header('Cache-control: max-age=31536000');
header('Expires: ' gmdate('D, d M Y H:i:s', (TIMENOW 31536000)) . ' GMT');
header('Content-disposition: inline; filename=' $row['filename']);
header('Content-transfer-encoding: binary');
header('Content-Length: ' strlen($row['filedata']));
header('Last-Modified: ' gmdate('D, d M Y H:i:s'$row['dateline']) . ' GMT');
$extension trim(substr(strrchr(strtolower($row['filename']), '.'), 1));
if (
$extension == 'jpg' OR $extension == 'jpeg')
    
header('Content-type: image/jpeg');
else if (
$extension == 'png')
    
header('Content-type: image/png');
else
    
header('Content-type: image/gif');

echo 
$row['filedata']; 
Reply With Quote
  #5  
Old 01-16-2007, 08:24 PM
AutomatikStudio's Avatar
AutomatikStudio AutomatikStudio is offline
 
Join Date: Dec 2003
Posts: 229
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's so odd. That very thing doesn't work for me. It's not throwing any errors and if I remove the header() stuff it displays the contents (letters/numbers) of the 'filedata' field.

Could it be something with my version of PHP/MySQL?

I'm running PHP 5.1.6 and MySQL 4.1.2-standard.
Reply With Quote
  #6  
Old 01-16-2007, 08:34 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am using PHP 5.1 with MySQL 5.

However, if the avatars are shown fine in your forum, then they should show using this script. I "adapted" the code found in vBulletin's image.php.

Which brings me to the next point, why don't you use image.php directly?:

http://www.nuhit.com/forums/image.php?userid=86
Reply With Quote
  #7  
Old 01-16-2007, 09:01 PM
AutomatikStudio's Avatar
AutomatikStudio AutomatikStudio is offline
 
Join Date: Dec 2003
Posts: 229
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I'm ultimately wanting to resize the avatars to various sizes depending on their locations throughout the site...so I'm wanting to pass the image through my GD resizing stuff.
Reply With Quote
  #8  
Old 01-16-2007, 09:09 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, I see.

You could save the data returned by the query into a local file in your server and compare it with the file returned by image.php, they should be binarily the same.
Reply With Quote
  #9  
Old 01-16-2007, 09:53 PM
AutomatikStudio's Avatar
AutomatikStudio AutomatikStudio is offline
 
Join Date: Dec 2003
Posts: 229
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ElfMage View Post
Oh, I see.

You could save the data returned by the query into a local file in your server and compare it with the file returned by image.php, they should be binarily the same.
Ah. Any tips on doing that?
Reply With Quote
  #10  
Old 01-16-2007, 09:58 PM
ElfMage ElfMage is offline
 
Join Date: Jul 2006
Location: Miami
Posts: 206
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could do this:

$filename = 'my_' . $row['filename'];
$fp = fopen( $filename, 'wb' );
if ($fp)
{
fwrite( $fp, $row['filedata'] );
fclose( $fp );
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:47 AM.


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.06191 seconds
  • Memory Usage 2,285KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete