<?PHP
if($action == "Update my Profile!" || $action == "do_profile_login") {
$dir = @opendir("database") or die("Error opening directory");
$found = false;
while ( $dir_name = readdir($dir) ) {
list($db_id, $db_email) = explode("]", $dir_name);
$db_id = substr($db_id, 1);
if ( $db_email == "$email" ) {
$found = true;
break;
}
}
}
if ("$action" == "do_profile_login" ) {
if ($found) {
$fd = fopen("database/$dir_name", "r");
$contents = fread ($fd, filesize("database/$dir_name"));
$delimeter = chr(135);
$pieces = explode("$delimeter", $contents);
if ($pieces[3] == $password) {
require("html/profile_update.html");
} else {
echo "Wrong Pass";
}
fclose ($fd);
} else {
print "Your profile was not found!";
}
} elseif ($action == "Update my Profile!") {
//We will now check if the user is attempting to upload something. If he is we will validate the upload ,if anything is wrong return to the registration form with an error msg.
if (!empty($img_name)) {
$img_info = GetImageSize($img);
if ($img_info[0] >= 318 or $img_info[1] >= 280) {
$error = '<b><font face="Arial, Helvetica, sans-serif">Error: Pic exceeds the maximum pixel dimension of 318X280!</font></b>';
include("html/register_form.html");
exit();
} elseif ($img_info[2] != "1" && $img_info[2] != "2") {
$error = '<b><font face="Arial, Helvetica, sans-serif">Error: The pic is not in jpg or gif format!</font></b>';
include("html/register_form.html");
exit();
}
} elseif (empty($Name)) {
//End upload validation
//Now we will validate all other data, if anything is wrong return to the registration form with an error msg.
$error = '<b><font face="Arial, Helvetica, sans-serif">Error: You did not give us your name!</font></b>';
require("html/profile_update.html");
exit();
} elseif (empty($E_Mail)) {
$error = '<b><font face="Arial, Helvetica, sans-serif">Error: You did not give us your e-mail address!</font></b>';
require("html/profile_update.html"); exit();
} elseif (strpos($E_Mail, chr(64)) === false) {
$error = '<b><font face="Arial, Helvetica, sans-serif">Error: The e-mail address you supplied is invalid!</font></b>';
require("html/profile_update.html");
exit();
} elseif (!empty($img_name)) {
//End data validation
//If the user wants to upload something we will now copy it from his HD to the server. We will also delete the previous image if any.
if(!empty($pieces[14])) {
unlink("mem_pics/[$db_id]$pieces[14]") or die("Unable to delete your previous pic");
}
copy("$img", "mem_pics/[$db_id]$img_name") or die("An error ocurred why attempting to upload your pic.");
}
//End file upload/deletion
//At this point the user has past all validation verification, we will now delete their past profile, and create a new one.
unlink("database/[$db_id]$db_email") or die("Unable to update your profile.");
$new_db = fopen("database/[$db_id]$E_Mail", "w");
fputs($new_db, "$Name$delimeter$E_Mail$delimeter$Date_Of_Birth$delimeter$password$delimeter$country$delimeter$city$delimeter$Sex$delimeter$Status$delimeter$mobno$delimeter$SeeMobMo$delimeter$website$delimeter$chatnick$delimeter$favchan$delimeter$comments$delimeter$img_name$delimeter$img_info[3]$delimeter");
//End of profile update
echo "Success $Name!!!, your profile was updated";
} else {
require("html/profile_login.html");
}
?>