<?php session_start(); // Must start session first thing // Here we run a login check // Here we run a login check $toplinks = ""; if (isset($_SESSION['id'])) { // Put stored session variables into local php variable $userid = $_SESSION['id']; $username = $_SESSION['username']; $toplinks = '<div id="Top_Links"><a href="logout.php">Log Out </a> <a href="member_account.php">My Account </a> <a href="member_profile.php?id=' . $userid . '">' . $username . '</a> </div>'; } else { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } // Place Session variable 'id' into local variable $id = $_SESSION['id']; // Process the form if it is submitted if ($_FILES['uploadedfile']['tmp_name'] != "") { // Run error handling on the file // Set Max file size limit to somewhere around 120kb $maxfilesize = 120000; // Check file size, if too large exit and tell them why if($_FILES['uploadedfile']['size'] > $maxfilesize ) { echo "<br /><br />Your image was too large. Must be 100kb or less, please<br /><br /> <a href=\"edit_pic.php\">click here</a> to try again"; unlink($_FILES['uploadedfile']['tmp_name']); exit(); // Check file extension to see if it is .jpg or .gif, if not exit and tell them why } else if (!preg_match("/\.(gif|jpg)$/i", $_FILES['uploadedfile']['name'] ) ) { echo "<br /><br />Your image was not .gif or .jpg and it must be one of those two formats, please<br /> <a href=\"edit_pic.php\">click here</a> to try again"; unlink($_FILES['uploadedfile']['tmp_name']); exit(); // If no errors on the file process it and upload to server } else { // Rename the pic $newname = "pic1.jpg"; // Set the direntory for where to upload it, use the member id to hit their folder // Upload the file if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "memberFiles/$id/".$newname)) { echo "Success, the image has been uploaded and will display to visitors!<br /><br /> <a href=\"member_account.php\">Click here</a> to return to your profile edit area"; $file="memberFiles/$id/".$newname; $sql="INSERT INTO file (path) VALUES ('$file')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "<font size = '5'><font color=\"#0CF44A\">SAVED TO DATABASE"; } else { echo "There was an error uploading the file, please try again. If it continually fails, contact us by email. <br /><br /> <a href=\"member_account.php\">Click here</a> to return to your profile edit area"; exit(); } } // close else after file error checks } // close if post the form ?>
$id
$userid
$username.jpg
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)