Page 1 of 2
Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 6:08 am
by zbdblues
Hello, i'm very new to php. I have a php 'profiles' script which gives a user log in, a profile page and a blog and forums.
I have now included an extra page and have spent nearly 48 hours getting it right, it's looking pretty good but i'm stuck on one issue.
On the left of the page i have included a small frame and i wish to display the logged in users avatar in that space.
The page i created is for example /folder/index.php and the users profile is /users/username/image. But there is also a separate folder /thumbs/(various other folders!).
What bit of code would i put into the page frame to include the signed in users avatar?
Your help would be very much appreciated, thanks.
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 6:20 am
by jackpf
Code: Select all
<img src="/users/username/image.jpg" alt="Avatar!" />
Like that??
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 6:23 am
by zbdblues
Well, no because that will give everyone who goes to that page the image url that i put in there. I need it to display individual user id's so that each person sees there own avatar.
So i'm looking for a bit of php code which will call the image of the individual user, according to who is logged in.
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 6:26 am
by jackpf
Oh right. Pardon me.
Well, store the filename of their avatar in the database. And then link to that image.
Hello
Posted: Tue Aug 18, 2009 6:27 am
by tajiknizam
Y dont u put the site adress
mean some thing like this
http://youdomain.com/users/images/(userPic.gif)
try it,. it works
Hello
Posted: Tue Aug 18, 2009 6:31 am
by tajiknizam
another solution s that, u put the avatar in the database
Make a BLOB field in ur Database table, so u can have the users avatar there,
or f u dont do so, do make a text feild, and store the link 4 the image
<img src="
http://yourdomain.com/users/images/john.jpeg">
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 7:02 am
by zbdblues
Hello, thanks for your answers so far but i don't think i've explained myself properly because all of your answers will leave everyone who logs in with one persons image and not their own individual image. So for example i could link to an image and that same image will show to everyone. But i need a bit of code which will call the image of the particular user that logs in. So it would be pointless putting eg. john.jpg, because everyone will get john.jpg. I need something which will replace the john.jpg which tells the script to get the individuals image to display.
So if i have users john, james, and janet, and they all log into the same page, the image is different for each one of them, displaying their own avatar.
Or another way of putting it, i want the page to recognise that user 'A' has logged in, so find his avatar and display it.
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 7:19 am
by mrvijayakumar
Try this,
Once user upload their avatar, just change the name of avatar with unique name. Once u get new user, their details will be added into your Database with unique ID. That ID can be used as file name of avatar. Or if u found unsecured by displaying unique ID as filename. Then encrypt the ID by using md5() function on php. No one can't track the original ID.
I will explain u with one example,
New user ID is 256 (assume like this). This user ID 256 is uploading his/her avatar. He/She will upload from his desktop with his/her name or any other. Assume filename as 'vijay.jpg'. While storing into our server, change the filename 'vijay.jpg' to '256.jpg', If u found, its unsecure, md5() the 256. U will get something like 'f718499c1c8cef6730f9fd03c8125cab', Store it as 'f718499c1c8cef6730f9fd03c8125cab.jpg'. Finally store this filename 'f718499c1c8cef6730f9fd03c8125cab.jpg' in database with his/her unique ID.
Once he/she logging in, call the avatar(filename) name from database. Problem solved now.
I think u got some related answer.. Reply me.
Cheers,
Vijaya Kumar S
Web Developer, +91 9952838699,
http://www.vijayakumar.org
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 7:35 am
by zbdblues
Hi Vijay, i did mail you hopefully you'll get that. Your solution means i have to manually edit everyone who signs up which is not going to be possible.
What i'm looking for, and i know it can be done because i have seen it done in other scripts, is a simple bit of code to replace src="image/image.gif".
Something like (i don't know php, so this is made up!) src="get-user-image"
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 7:51 am
by mrvijayakumar
Hi zbdblues, send me some sample code here. I will review it and reply u back with gud stuff.
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 7:52 am
by jackpf
I've explained how to do it. And so has tajiknizam.
You have to store each user's image's filename in the database. Then you have a directory of images, and link to the directory, plus the user's avatar's filename.
Or if the user's avatar includes their username, link to the avatar, plus however you're storing usernames.
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 8:02 am
by juma929
Hello,
Other users have told you how to go around producing this, I am just adding onto this.
As mentioned, a useful way to go around this kind of issue is to store the details of the user image in the database in a field such as 'avatar'. In there you could have 'billy_avatar.jpg' and in your PHP code you could have something along the lines of:
Code: Select all
echo '<img src="images/whatever/anotherfolder/evenmore/' . $avatar_image . '"/>';
Another alternative is just using your users login as the image name, im guessing your logins are all unique right?

So if a user uploads an avatar, make it auto name the image to the users login name and then your code should be able to use this to pull the image through. This has the benefit of less fields in the database but it makes it that slight bit easier for outside users to get peoples images (although its pretty simple even if the name was database stored), unless you maybe link through another PHP page etc but I could go on all day and think its time to be quiet after all, the solution has already been mentioned before my post!!
Thanks

Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 8:13 am
by zbdblues
Juma and everyone, thank you very much. I know you all think you gave me the answer, but yours is the answer i wanted because as i said, i don't know about php code.
It's that all important way as to how to write the instruction....echo!
I'm going to try that now, thanks. That second part of your answer sounds interesting to me because this script that i've added mine to is complex. It goes through many pages before arriving at an actual avatar. The problem is that i don't know how to do what you suggested!
Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 8:30 am
by juma929
Hello,
Please dont take this the wrong way, but if you are intending on your website to be used frequently and have high hopes for it. It may be worth while asking around on here for somebody who has the time to help you a little more as it seems although you are trying your hardest, you could do with a little assistance with PHP for the time being.
I think the guys on here understandably are expecting the people who post to understand the elements of the language such as echo and the use of variables and thats why some posts lack any kind of further detail.
If you need any more help at all, please get in touch and whenever I have the time ill chip in

.
Thanks

Re: Hello, can anyone help me with a bit of code please?
Posted: Tue Aug 18, 2009 8:36 am
by jackpf
I know you all think you gave me the answer, but yours is the answer i wanted
I did actually tell you that about 11 posts ago.........
Store the filename in a database did I not say?