runnerjp Posted May 10, 2007 Share Posted May 10, 2007 hey guys,,,,i have tried a few ways of doing this but need help... i need it so that users have there own profile pictures up, need them putting into a database, rewriten when new 1ns added then when user loggs in there profile picture will be displayed what would the code look like? Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/ Share on other sites More sharing options...
runnerjp Posted May 10, 2007 Author Share Posted May 10, 2007 <?php header('Content-Type: text/plain'); echo "This Page Shows How Uploads Works\n"; print_r($_FILES); move_uploaded_file($_FILES["profile_image"]["tmp_name"], "profileimages/" . $_FILES["profile_image"]["name"]); if ($_FILES["profileimages"]["error"] > 0) { echo "Apologies, an error has occurred. Error Code: " . $_FILES["profileimages"]["error"]; } else { move_uploaded_file($_FILES["profileimages"]["tmp_name"], "profileimages/" . $_FILES["profileimages"]["name"]); } if (($_FILES["profileimages"]["type"] == "image/gif") || ($_FILES["profileimages"]["type"] == "image/jpeg") || ($_FILES["profileimages"]["type"] == "image/png" ) && ($_FILES["profileimages"]["size"] < 10000)) { move_uploaded_file($_FILES["profileimages"]["tmp_name"], "profileimages/" . $_FILES["profileimages"]["name"]); } else { echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb"; } ?> i have this but how do i add it to my database and a unique id number??? Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-249779 Share on other sites More sharing options...
trq Posted May 10, 2007 Share Posted May 10, 2007 You'll want to add the file path to your database, along with the id of the user uploading the file. Assuming you have a login system using sessions, just grab the id from the $_SESSION array. If its not in the session array, put it there at login. Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-249785 Share on other sites More sharing options...
runnerjp Posted May 10, 2007 Author Share Posted May 10, 2007 ok and how would i do that lol... and im using cookies Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-249787 Share on other sites More sharing options...
trq Posted May 10, 2007 Share Posted May 10, 2007 Do you need a tutorial on how to insert data into a database? Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-249790 Share on other sites More sharing options...
runnerjp Posted May 11, 2007 Author Share Posted May 11, 2007 would be nice lol mainly images Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-250353 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 You don't insert the image into the database, just the path or filename maybe add a new column in the users table called avatar, or image. Then you would insert profileimages/" . $_FILES["profile_image"]["name"] into the database. Or if all images are going to be stored in the same place, simply add the filename to the database and when you display their information you simply have variable called $image_dir='profileimages/'; and concatenate that variable to the variable pulled out of the database for that user e.g. while($row=mysql_fetch_object($query_variable_here)) { $image=$image_dir.$row->avatar; // the rest of the while loop here pulling out the other data } That would give you a path of profileimages/filename.jpg Obviously adjust your paths and such, but that is the basic idea Nate Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-250369 Share on other sites More sharing options...
runnerjp Posted May 11, 2007 Author Share Posted May 11, 2007 so would something like this do <? //UPLOAD CHECK $table_name = "$tbl_images"; $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect to database."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT image_id, directory, url, image FROM $table_name WHERE image_id = \"$comm_id\" "; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); $num=mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $image_id = $row['image_id']; $directory = $row['directory']; $url = $row['url']; $image = $row['image']; } if(isset($image)) { $location ="$directory/$image"; $showimg="../$url/$image"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-250515 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.