Hello, I have a forum and i want to have a avatar system for each users avatar to appear on the side of his thread. but i am newbie to php and don't know how to do this. Can source code for this. Thankyou,
Quickbird

It would help if we had the code that you already created for the user, so we can better integrate ours.

You have two options:

- Store the image itself in the database.
- Store the image name in the database.

I prefer the later, because while it does require to do a bit more of job, you can still include it anywhere, and I think it woudn't cause many resource problems like storing the image itself would do.

You should really get a handle of the basics thought. Doing this requires the use of sessions when the user is online, and pulling the right information from the database when the user makes a message (for example).

Quickbird,

There's every chance that the forum is one of the big open source systems - eg. phpBB, phpNuke, yaBB, vBulletin etc etc.

If so, then first look in the admin control panel and see if you just need to throw a switch to turn avatars on.

Failing that, you need to go to the "mods" section of the relevant forum system's web site and find a mod which adds avatars.

There's little point making a general request here for "source code for this", especially when we don't know what "this" is. The solution to your problem will be very specific to the system employed.

Airshow

It would help if we had the code that you already created for the user, so we can better integrate ours.

The code is below but I don't know how to provide an Upload system.

<?php
    $linkIDmember = @mysql_pconnect("localhost", "user_name", "password");
    mysql_select_db("sauhnik_forums", $linkIDmember);
    $sql2 = "SELECT * FROM ibf_members WHERE id=$mid"; // note double quotes
    $result2 = mysql_query($sql2);
    list($id, $name, $mgroup, $password, $email, $joined, $ip_address, $avatar, $avatar_size, 
$posts, $aim_name, $icq_number, $location, 
$signature, $website, $yahoo, $title, $allow_admin_mails, $time_offset, $interests,
 $hide_email, $email_pm, $email_full, $skin, $warn_level, $language, $msnname,  
    $last_post, $allow_post, $view_sigs, 
$view_img, $view_avs, $view_pop, $bday_day, $bday_month, $bday_year, $new_msg, $msg_from_id, $msg_msg_id, $msg_total, $vdirs, $show_popup, $validate_key, 
$prev_group, $new_pass, $misc, $last_visit, $last_activity, $dst_in_use, $view_prefs, 
$coppa_user, $mod_posts, $auto_track, $date_modified) = mysql_fetch_row($result2);
?>

<table border=1 width=100% style='font-family:Verdana;font-size:11px'>
<TR><TH>Name</TH><TH>Comment</TH></TR>
<?php
while($row1 = mysql_fetch_object($r1))
  {
  ?>  
  <tr>
    <td width=10%>
    <?php 
    if ($avatar == "")
        {
            print "";
        }
        else
        {
            $avivars  = "$avatar";
            $pieces = explode(":", $avivars);
            if ($pieces[1] == "")
                {
                    print "<img src=$avatar>";
                }
                else
                {
                    print "<img src=http://www.gamingz.com/forums/uploads/$pieces[1]>";
                }
        }
    ?>

    <a href='http://www.gamingz.com/forums/index.php?act=Profile&CODE=03&MID=<?php echo $row1->mid ?>' target='_blank'><?php echo $row1->name ?></a></td>
    <td valign=top width=90%><?php echo $row1->comment ?></td>
  </tr>
<?php
   } ?>

This is my Avatar script but
I don't know whats wrong with the script. It connects to my database succesfully, but it won't upload pics, neither to the folder directed, which is avatars/

<html>
<head>
<title>Avatar Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#FFFFFF" text="464646" link="#468DD5" vlink="#468DD5" alink="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?
//include dBase connect
include('./db.php');

//user defined variables
$sizelim = "yes"; //Do you want size limit, yes or no
$size = $avatarSize; //What do you want size limited to be if there is one
$maxHeight = $avatarHeight; //set the max height
$maxWidth = $avatarWidth; //set max width
$avatarPath = $abpath . "/avatars";
// Connect to database
$link = dbConnect();

if($action == ""){
?>
<table width="450" border="0" cellspacing="0" cellpadding="10">
  <tr>
    <td><center>
        <font size="4" face="Verdana, Arial, Helvetica, sans-serif"><b>Avatar Upload</b></font>
      </center><br>
      <font face="Verdana, Arial, Helvetica, sans-serif">Image must be a .JPG
      file<br>
      Dimensions can't exceed <? echo $avatarWidth." wide x ".$avatarHeight." tall pixels"; ?><br>
      File size can't be over <? echo $avatarSize; ?> bytes</font><br>
      <form method="POST" action="upload.php" enctype="multipart/form-data">
        <p><font face="Arial, Helvetica, sans-serif">Image to upload:</font><br>
<input type="file" name="img1" size="30"><br>
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="action" value="uploadImage">
</form>
      <br>
      <center>
        <font size="2" face="Arial, Helvetica, sans-serif"><a href="javascript:self.close()">close
        window</a></font>
</center></td>
  </tr>
</table>
<?
exit;
}
//all image types to upload
$cert1 = "image/jpeg"; //Jpeg type 1

$log = "";
$posted = time();

//begin upload
//check dimensions
$image_info = getimagesize($img1);
$img1_type = $image_info['mime'];
//compare uploaded image to our variables
if(($image_info[1]>$maxHeight) or ($image_info[0]>$maxWidth)){
   $log.= "Dimensions are greater than $maxWidth x $maxHeight<br>";
}
//checks if file exists
if ($img1_name == "") {
   $log.= "No file selected for upload<br>";
}
/*
if ($img1_name != "") {
 //checks if file exists
   if (file_exists("$avatarPath/$img1_name")) {
      $log.= "File already existed<br>";
   }
}
*/
//checks if files to big
if ($sizelim == "yes") {
   if ($img1_size > $size) {
      $log.= "Image file size was too big<br>";
   }
}

//if we have errors, send them to the user and exit
if($log!=""){
echo "<table width=\"450\" border=\"0\" cellspacing=\"0\" cellpadding=\"10\">";
echo "<tr>";
echo "<td>";
echo "<center><font size=\"4\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b>Avatar Upload</b></font></center><br>";
echo "<font face=\"Arial, Helvetica, sans-serif\"><b><u>Results:</u></b><br>$log<br><br><br><center><a href=\"javascript:history.back(-1)\"><< go back and try again</a><br><br><font face=\"Arial, Helvetica, sans-serif\" size=\"2\"><a href=\"javascript:self.close()\">close window</a></font></center></font>";
echo "</td>";
echo "</tr>";
echo "</table>";
exit;
}

//Checks if file is an image
if ($img1_type == $cert1) {

   $img1_name = "$userdetails[0]" . "-" . $posted . ".jpg";
   @copy($img1, "$avatarPath/$img1_name") or $log .= "Couldn't copy image to server<br>";

   //make the avatar link for the db
   $avatarLink = "$installDirectory"."avatars/"."$img1_name";

   // set avatar location using the username cookie
   $query = "UPDATE forumUsers SET avatarURL = '$avatarLink' WHERE username = '$userdetails[0]'";
   // Execute query
   if(!mysql_query($query)) {
    echo mysql_error($link);
   }
   if($log == ""){
   $log .= "<b>Image was uploaded!</b><br>";
   }
}else{
$log .= "File is not a non-progressive JPG image<br>";
}
// Close link to database server
mysql_close($link);
?>
<table width="450" border="0" cellspacing="0" cellpadding="10">
<tr>
<td>
<center><font size="4" face="Verdana, Arial, Helvetica, sans-serif"><b>Avatar Upload</b></font></center>
<br>
<?
echo "<font face=\"Arial, Helvetica, sans-serif\"><b><u>Results:</u></b><br>$log<br><br><br><center><a href=\"javascript:self.close()\">close window</a></center></font>";
?>
</td>
</tr>
</table>
<body>
<html>

Any help will be appreciated........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.