TeddyKiller Posted March 3, 2010 Share Posted March 3, 2010 How do I do it. Well, you may be thinking.. what am I asking? I have a few questions. 1. A user has a profile where they can upload photo's, how is this done? 2. The users profile has their photo galleries, which they can view their photo's/or others can view, how is this done? 3. The user can view their photo's (related to above) and select a default profile picture, how is this done? 4. On the homepage, it'll display random 8 maybe 12 members with there default picture shown, how is this done? Can anyone help me explain this? It should be straight forward. The method is similar to a social networking website. I don't expect code, just an explanation good enough for me to understand, though you can supply code if your heart desires you to do so Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/ Share on other sites More sharing options...
Wolphie Posted March 3, 2010 Share Posted March 3, 2010 Well to begin with you'd require a user to create a new account, once this has been done you should be storing information specific to them in the database. Once this data is in the database it can now be used to construct a profile specific to each user. Each user should have a unique ID to identify them amongst other users (important for profiles, e.g. http://somesite.com/profile.php?id=54, 54 being the ID of the user). This link would then take them or another person to their profile page that contains information specific to them. If it is their page, then you should have some kind of administration facility where users can upload files (you're after just image files, example code can be found here: http://www.w3schools.com/PHP/php_file_upload.asp). Once one or more images have been uploaded, given a unique ID along with the ID of the user who uploaded them, you can now proceed to turn it into a gallery (http://somesite.com/gallery.php?id=54, again 54 being the ID of the user). When you create the gallery script you can pull images from the database specific to that user (i.e. the ones that user has uploaded). With this in mind you can add radio buttons for each image, giving the radio buttons the same IDs as you gave each individual image. This will allow you to submit a form with the selected radio button so you can then change the users default picture in the database by pulling only that image. Pulling random users from the database is quite simple, use the MySQL RAND() function and LIMIT clause to pull a random number of records (users) and display any relevant information about them that you see fit. Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1020866 Share on other sites More sharing options...
TeddyKiller Posted March 3, 2010 Author Share Posted March 3, 2010 I've seen file uploads, and I know how to use them. However.. how would it be set to that specific user. so.. gallery.php?id=54, how would that get the images related to that users id. By what you mean default profile pic. Would the user choose a picture from their gallery to be default. Check the box or whatever.. and it'll insert into the database the link to that picture? eg: /images/upload/sdogosdgsd.jpg (again this would be related to the other question ^^ because I'm not sure how the files would go out etc) Then when you call the profile pic.. just.. display whats on the link basically? It'll mean resizing it of course. Then same goes for the 8-12 randoms on the homepage? (It'll only display the users picture) Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1020881 Share on other sites More sharing options...
Wolphie Posted March 3, 2010 Share Posted March 3, 2010 Sorry, I'll be more specific. Let's say you have 2 database tables, one named users and the other named images. Each user would be given a unique ID when they register, and the user table would contain this unique ID and all of their profile information. The images table would also contain a unique image ID, and ALSO a user ID field (which isn't a primary key), so that when a user uploads an image, that image is given a unique ID and the ID of the user is also inserted for that particular image(s). This is known as a relational database. In the images table, you would also have information such as file name, file type, file size and the path to the file. In the users table you would have something like avatar_id which would correspond to the image ID they selected from the images table. You can then select this record and all of the information with it, including the path which will allow you to display it on screen. Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1020886 Share on other sites More sharing options...
TeddyKiller Posted March 3, 2010 Author Share Posted March 3, 2010 Ok so that tutorial you gave me, will upload the image to a directory called "Upload" I'll add a piece of code so that when a user uploads an image, not only does it go to the directory, it'll insert specific information into the database including the URL of the image? If so, then it makes sense. Is it possible to protect people from viewing anything in the uploads folder on it's own? Some people like their images to remain private, so could that be possible? Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1020894 Share on other sites More sharing options...
Wolphie Posted March 3, 2010 Share Posted March 3, 2010 Yes it is possible, just change the permissions of the folder. Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1020910 Share on other sites More sharing options...
TeddyKiller Posted March 10, 2010 Author Share Posted March 10, 2010 Lets say I'm wanting 12 photos on the homepage, if there isn't enough users, eg: there is 1 user, to display the rest of the 11 spaces with a default "No Photo" image which I have made, and if there is 12 or more users, that no photo will not get displayed (Unless the user hasn't uploaded a photo) How would I go about that? Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1024233 Share on other sites More sharing options...
Wolphie Posted March 10, 2010 Share Posted March 10, 2010 You check the profile picture field in the user table for a value. For example <?php $sql = mysql_query("SELECT avatar FROM users ORDER BY RAND() LIMIT 12"); if (mysql_num_rows($sql) > 0) { while ($item = mysql_fetch_array($sql)) { if ($item['avatar'] == '') { echo 'nopic.png'; } else { echo 'profilepic.png'; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1024264 Share on other sites More sharing options...
TeddyKiller Posted March 10, 2010 Author Share Posted March 10, 2010 I understand, that's the method I thought, this is slightly off topic, but how would I rearrange it so that it's two rows, 6 images, and then 6 images underneath. Also.. resizing the images, this could mean cropping.. but lets say a long avatar or profile picture got picked out how would I change it so that it is a square image without distorting it and having it at a particular size. Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1024269 Share on other sites More sharing options...
TeddyKiller Posted March 10, 2010 Author Share Posted March 10, 2010 The code you supplied with the nessecary changes will display random avatars of people who are registered. Though.. if there isn't 12 people registered, theres lets say 4, it'll display the 4 users avatars, and then 8 no pic avatars. Also, it's not showing anything as a photo.. it just says the alt descripton. Can you help? <?php $sql = mysql_query("SELECT Avatar FROM users WHERE Activated = '1' ORDER BY RAND() LIMIT 12"); if (mysql_num_rows($sql) > 0) { while ($item = mysql_fetch_array($sql)) { if ($item['Avatar'] == '') { echo '<img src="profile/photos/default/default.jpg" alt="default" />'; } else { echo "<img src=\"".$item['Avatar']."\" alt=\"user\" />"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/193992-users-photo-gallery-with-default-picture-for-their-profile/#findComment-1024425 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.