Two thing with these function don't work, it doesn't upload the file, or add the entry to the table. Not sure were i went worng....
New Functions:
<?
function show_uploadAvatar() {
if($form->num_errors > 0){
echo "<td><font size='2' color='#ff0000'>".$form->num_errors." error(s) found</font></td>";
}
echo "<form action='process.php' method='post' enctype='multipart/form-data'>";
echo "<p />";
echo "<label for='file'>Select a file:</label> <input type='file' name='image' id='file'><? $form->error('upload'); ?><br />";
echo "<input type='hidden' name='subupload' value='1'><input type='submit' value='Upload File'>";
echo "<p />";
echo "</form>";
}
/* database function */
public function addUserAvatarLocation($image_path,$image_name,$image_width,$image_height,$alt_tag_text) {
global $session;
$q = "INSERT INTO avatar_location (id,image_path,image_name,image_width,image_height,alt_tag_text,user_upld_by,upld_on) VALUES('',$image_path,$image_name,$image_width,$image_height,$alt_tag_text,$session->username,NOW())";
return mysql_query($q, $this->connection);
}
/* Session function */
public function userAvatarLocation($subimagename, $subimagewidth, $subimageheight, $subalttagtext){
global $database;
$subimagepath = "avatars/users/";
if($subimagepath && $subimagename && $subimagewidth && $subimageheight && $subalttagtext){
$database->addUserAvatarLocation($subimagepath, $subimagename, $subimagewidth, $subimageheight, $subalttagtext);}
/* Success! */
return true;
}
public function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
public function userAvatarUpload($image) {
global $form;
$field = "Upload";
//reads the name of the file the user submitted for uploading
$image=$_FILES[$image]['name'];
//if it is not empty
if ($image) {
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES[$image]['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwize we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
$form->setError($field, "* Not a Valid extension!");
}else{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=filesize($_FILES[$image]['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024) {
$form->setError($field, "* You have exceeded the size limit!");
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="avatars/users/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES[$image]['tmp_name'], $newname);
if (!$copied) {
$form->setError($field, "* Copy unsuccessfull!");
}
}
}
if($form->num_errors > 0){
return false;
}
/* Change Email */
if($image && $image_name){
$subAltTagText = $this->username;
$image_path = "avatars/users/";
//gets images stats
list($image_width, $image_height, $type, $attr) = getimagesize($newname);
$database->addUserAvatarLocation($image_path,$image_name,$image_width,$image_height,$subAltTagText);
}
/* Success! */
return true;
}
/* Process function */
public function procUserAvatarUpload(){
global $session, $form;
/* Account edit attempt */
$retval = $session->userAvatarUpload($_POST['image']);
/* Account edit successful */
if($retval){
$_SESSION['useredit'] = true;
header("Location: ".$session->referrer);
}
/* Error found with form */
else{
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}
?>
Database connection:
<?php
class MySQLDB
{
var $connection; //The MySQL database connection
var $num_active_users; //Number of active users viewing site
var $num_active_guests; //Number of active guests viewing site
var $num_members; //Number of signed-up users
/* Note: call getNumMembers() to access $num_members! */
/* Class constructor */
public function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
?>