justAnoob Posted February 4, 2009 Share Posted February 4, 2009 Well my upload scipt is woking. I know I still have more work to do with it, but for right now, It Works!(Yippee). How difficult would it be to link the username of the person signed in, with the files that he/she uploaded. Right now, I can go look in the database and see a bunch of pictures, but have no idea who put them there. Is this too hard to accomplish? Here is the upload script so far. <?php session_start(); include ("upload_db_info.php"); if (!empty($_POST['upload'])) { extract($_POST); if(isset($_POST['upload']) && $_FILES['upload_file']['size'] > 0) { $fileName = $_FILES['upload_file']['name']; $tmpName = $_FILES['upload_file']['tmp_name']; $fileSize = $_FILES['upload_file']['size']; $fileType = $_FILES['upload_file']['type']; if ( file_exists($tmpName) ) { $content = file_get_contents($tmpName); } } else { unset($_SESSION['uploadcomplete']); $_SESSION['uploaderror'] = "Please select a picture."; header("location: http://www.----------.com"); exit(); } $fileName = mysql_real_escape_string($fileName); $fileSize = (int)$fileSize; $fileType = mysql_real_escape_string($fileType); $content = mysql_real_escape_string($content); $query = "INSERT INTO UploadedFiles (name, size, type, content)VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; $result = mysql_query($query)or die (mysql_error()); unset($_SESSION['uploaderror']); $_SESSION['uploadcomplete'] = "Your picture was uploaded to our system."; header("location: http://www.--------.com"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted February 4, 2009 Share Posted February 4, 2009 No, it's not hard. When you upload the file just get the userid from the session login (or wherever you have stored it) and insert it into a third table that contains the ids for the inserted images and the userid's. If you have no idea what i just said then maybe a 101 in db design would help you understand the structure, Google is your friend Quote Link to comment Share on other sites More sharing options...
justAnoob Posted February 4, 2009 Author Share Posted February 4, 2009 I understand and that does make sense. If I could do that then I should also be able to get the actual username from the page and have that uploaded to my pic database as well, correct? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted February 4, 2009 Author Share Posted February 4, 2009 Well, first of all. Am I on the right track? I created a session variable from my username variable. So when the user logs in, a new session is set. (id) <?php $_SESSION['id'] = "$username"; ?> Then in my upload script I added the following lines that are highlighted. <?php session_start(); include ("upload_db_info.php"); if (!empty($_POST['upload'])) { extract($_POST); if(isset($_POST['upload']) && $_FILES['upload_file']['size'] > 0) { $user = $_SESSION['id']; /////////////////////////////////// $fileName = $_FILES['upload_file']['name']; $tmpName = $_FILES['upload_file']['tmp_name']; $fileSize = $_FILES['upload_file']['size']; $fileType = $_FILES['upload_file']['type']; if ( file_exists($tmpName) ) { $content = file_get_contents($tmpName); } } else { unset($_SESSION['uploadcomplete']); $_SESSION['uploaderror'] = "Please select a picture."; header("location: http://www.--------.com"); exit(); } $user = mysql_real_escape_string($user); //////////////////////////// $fileName = mysql_real_escape_string($fileName); $fileSize = (int)$fileSize; $fileType = mysql_real_escape_string($fileType); $content = mysql_real_escape_string($content); $query = "INSERT INTO UploadedFiles (name, size, type, content, user) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$user')"; ///////////////////////////added user and $user $result = mysql_query($query)or die (mysql_error()); unset($_SESSION['uploaderror']); $_SESSION['uploadcomplete'] = "Your picture was uploaded to our system."; header("location: http://www.--------.com"); exit(); } ?> I do not get any errors but the user field in my database is not being filled with the username. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted February 4, 2009 Author Share Posted February 4, 2009 Sorry, had to bump it up. I need to leave for work in 1 hour, and this will bother me all day. Quote Link to comment Share on other sites More sharing options...
peranha Posted February 4, 2009 Share Posted February 4, 2009 you are not setting the $user variable. You set $_SESSION['id'] to $username, try changing $user to $username and see what that gets you I see you are setting $user with $user $user = mysql_real_escape_string($user) should it be $user = mysql_real_escape_string($username) Quote Link to comment Share on other sites More sharing options...
justAnoob Posted February 4, 2009 Author Share Posted February 4, 2009 Thanks for the suggestion, but what I had did actually work. I just forgot to re-upload my login script to my server. I feel stupid. Thanks though. Quote Link to comment Share on other sites More sharing options...
peranha Posted February 4, 2009 Share Posted February 4, 2009 Thanks for the suggestion, but what I had did actually work. I just forgot to re-upload my login script to my server. I feel stupid. Thanks though. Not a problem, I hate when that happens to me also. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.