Someone please help me. I have the following code and everything works well except when I delete the users current photo and then upload a new one, is still shows the users orginal photo until i refresh the page manually. I dont get it please help me here...
session_start();
header("Content-type: image/jpeg");
require('../Connections/themeetmarket.php');
// *** Logout the current user.
$FF_Logout = $HTTP_SERVER_VARS['PHP_SELF'] . "?FF_Logoutnow=1";
if (isset($HTTP_GET_VARS['FF_Logoutnow']) && $HTTP_GET_VARS['FF_Logoutnow']=="1") {
session_unregister("MM_Username");
session_unregister("MM_UserAuthorization");
$FF_logoutRedirectPage = "/login.php";
// redirect with URL parameters (remove the "FF_Logoutnow" query param).
if ($FF_logoutRedirectPage == "") $FF_logoutRedirectPage = $HTTP_SERVER_VARS['PHP_SELF'];
if (!strpos($FF_logoutRedirectPage, "?") && $HTTP_SERVER_VARS['QUERY_STRING'] != "") {
$FF_newQS = "?";
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
if($key != "FF_Logoutnow"){
if (strlen($FF_newQS) > 1) $FF_newQS .= "&";
$FF_newQS .= $key . "=" . urlencode($val);
}
}
if (strlen($FF_newQS) > 1) $FF_logoutRedirectPage .= $FF_newQS;
}
header("Location: $FF_logoutRedirectPage");
exit;
}
// *** Restrict Access To Page: Grant or deny access to this page
$FF_authorizedUsers=" ";
$FF_authFailedURL="/login.php";
$FF_grantAccess=0;
session_start();
if (isset($HTTP_SESSION_VARS["MM_Username"])) {
if (true || !(isset($HTTP_SESSION_VARS["MM_UserAuthorization"])) || $HTTP_SESSION_VARS["MM_UserAuthorization"]=="" || strpos($FF_authorizedUsers, $HTTP_SESSION_VARS["MM_UserAuthorization"])) {
$FF_grantAccess = 1;
}
}
if (!$FF_grantAccess) {
$FF_qsChar = "?";
if (strpos($FF_authFailedURL, "?")) $FF_qsChar = "&";
$FF_authFailedURL = $FF_authFailedURL;
header("Location: $FF_authFailedURL");
exit;
}
$msg = "";
$showform = "";
//////////////////check if profile image exists ////////////////
$colname_Recordset1 = "1";
if (isset($HTTP_SESSION_VARS['username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['username'] : addslashes($HTTP_SESSION_VARS['username']);
}
mysql_select_db($database_themeetmarket, $themeetmarket);
$chkimage = sprintf("Select * FROM users WHERE username='%s'", $colname_Recordset1);
$Recordset1 = mysql_query($chkimage, $themeetmarket) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
if ( 'thumb_noimage.jpg' == $row_Recordset1['image'] ) {
$showform = 'upload1.php';
$msg="No profile image exists, please upload one at this time.";
$profileimage ="<img src='" . "/members/thumb/" . $row_Recordset1['image'] . "'border=1 alt=\"" . $row_Recordset1['username'] ." Profile Picture" . "\"";
} else {
$showform = 'upload2.php';
$msg="This is your profile image, please delete it before uploading a new one.";
$profileimage ="<img src='" . "/members/thumb/" . $row_Recordset1['image'] . "'border=1 alt='" . $row_Recordset1['username'] ."_Profile Picture" . "'";
}
///////////////// end check ////////////////////////////////////
///////////////IMAGE UPLOAD SCRIPT///////////////////
if (isset($_POST['upload'])) {
$maxfilesize=150000;
$imsize=$_FILES['file']['size'];
$immaxwidth="600";
$immaxheight="600";
$picname = $_FILES['file']['name'];
$updir = "/home/public_html/members/photo";
//check image width & height
$imgsize = GetImageSize($file);
//== check size 0=width, 1=height
if (($imgsize[0] > $immaxwidth) || ($imgsize[1] > $immaxheight)){
$msg ="ERROR - Image width and height allowed is $immaxwidth by $immaxheight px. Please select an image that meets this requirement.";
}
//end dimension check
else if (file_exists("$updir/$picname")){
$msg = "ERROR - Your file was not saved!";
$msg = "File name already exists, please rename your file!";
unlink($_FILES['file']['tmp_name']);
}
else if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])){
$msg = "ERROR = You did not upload a file!";
unlink($_FILES['file']['tmp_name']);
}
else if ($_FILES['file']['size'] > $maxfilesize){
$msg = "ERROR - File is over 80k in size";
unlink($_FILES['file']['tmp_name']);
}
else if ($_FILES['file']['type'] != "image/pjpeg"){
$msg = "ERROR - This file type is not allowed. Only .jpg or .jpeg is allowed.";
unlink($_FILES['file']['tmp_name']);
}
// else here we go upload and save image to database
else {
move_uploaded_file($_FILES['file']['tmp_name'],"/home/public_html/members/photo/" . $_FILES['file']['name']);
////thumbnail script////
@$size = GetImageSize("/home/public_html/members/photo/" . $_FILES['file']['name']);
if ($size[2] == '2'){
@$source_id = imagecreatefromjpeg("/home/public_html/members/photo/" . $_FILES['file']['name']);
$dest_x = 60;
$dest_y = 70;
@$target_id = imagecreatetruecolor($dest_x, $dest_y);
@$target_pic = imagecopyresampled($target_id,$source_id, 0, 0, 0, 0, $dest_x, $dest_y, $size[0],$size[1]);
$test="imagejpeg";
}
if ($test == 'imagejpeg'){
//////////Rename Image/////////////
$flnm = $row_Recordset1['id'];
//list($parts) = explode(".",$_FILES['file']['name']);
$ending = array_pop(explode(".",$_FILES['file']['name'])); // get last part of $original_filename
$new_filename = $flnm. ".". $ending;
$tblname = "thumb_" . $flnm. ".". $ending;
///////////////////////////////////
@imagejpeg($target_id,"/home/public_html/members/thumb/thumb_" . $new_filename, 100);
$addthumb = sprintf("UPDATE users SET image='$tblname' WHERE username='" . $_SESSION['username'] . "'");
mysql_select_db($database_themeetmarket, $themeetmarket);
$Result2 = mysql_query($addthumb, $themeetmarket) or die(mysql_error());
}
////////Resize profile image large/////////////
@$size = GetImageSize("/home/public_html/members/photo/" . $_FILES['file']['name']);
if ($size[2] == '2'){
@$source_id = imagecreatefromjpeg("/home/public_html/members/photo/" . $_FILES['file']['name']);
$dest_x = 160;
$dest_y = 170;
@$target_id = imagecreatetruecolor($dest_x, $dest_y);
@$target_pic = imagecopyresampled($target_id,$source_id, 0, 0, 0, 0, $dest_x, $dest_y, $size[0],$size[1]);
$test="imagejpeg";
}
if ($test == 'imagejpeg'){
//////////Rename Image/////////////
$lrgname = $row_Recordset1['id'];
//list($parts) = explode(".",$_FILES['file']['name']);
$ending1 = array_pop(explode(".",$_FILES['file']['name'])); // get last part of $original_filename
$new_filename1 = $lrgname. ".". $ending1;
$tblname1 = "lrg_" . $lrgname. ".". $ending1;
///////////////////////////////////
@imagejpeg($target_id,"/home/public_html/members/photo/lrg_" . $new_filename1, 100);
$addimage = sprintf("UPDATE users SET photo='$tblname1' WHERE username='" . $_SESSION['username'] . "'");
mysql_select_db($database_themeetmarket, $themeetmarket);
$Result3 = mysql_query($addimage, $themeetmarket) or die(mysql_error());
unlink("/home/public_html/members/photo/" . $_FILES['file']['name']);
header("Location: /members/upload.php?");
}
}
}
if (isset($_POST['delete'])){
////// delete images off of server //////
unlink("/home/public_html/members/photo/" . $row_Recordset1['photo']);
unlink("/home/public_html/members/thumb/" . $row_Recordset1['image']);
/////////////////////////////////////////
$deleteimages = sprintf("UPDATE users SET photo='lrg_noimage.jpg', image='thumb_noimage.jpg' WHERE username='" . $_SESSION['username'] . "'");
mysql_select_db($database_themeetmarket, $themeetmarket);
$Result4 = mysql_query($deleteimages, $themeetmarket) or die(mysql_error());
header("Location: /members/upload.php?");
}
///////////update whois online//////////////
include ('/home/public_html/members/include/online.php');
////////////////////////////////////////////