Avatars?

Hi all,

I’m really knew to php and still learning so any help and suggestions are appreciated.

Basically what I’m trying to do is create a generic profile page that allows the selection of an image as an avatar.

I would like upload images to a directory and store the file path in the database but I’m not sure exactly how to go about doing this. I would then want to allow selection of images via a drop down and then save.

Can anyone point me in the right direction to start this process, or have any good tutorials etc.

Also, how tricky would this get if you were to upload several files (images) to the specified “avatar” directory via ftp instead of via a upload form, and still have all the images show in a drop down and be selectable?

I hope that made sense.

First thing’s first.

Are -YOU- going to be uploading all of the avatars, or are you wanting to allow your -USERS- to upload the avatars? Because those are two vastly different paths to take.

I would like to actually do both. Allow users to upload an avatar, but me as the site admin could add more via ftp directly or I could make my own admin upload form.

And you’re new to PHP…ok…what does that mean? You’re obviously versed in PHP enough to handle session management and database manipulation to create user entries…and that took me nearly a year to learn.

Being that I dont know what your programming level is, i’m going to give you a URL, and you’re going either tell me it made sense or it didnt :wink:

Handling File Uploads via POST

Since the first step to your problem is getting the pictures to the webhost (lets forget FTP for the moment), that should be your first stop (waits for the SitePoint Authors to pop in and plug their books).

Hi Star,

Yes I am new to php but I can handle the database manipulation etc like you said.

I’m actually enrolled in a “beginner-intermediate” class via a local school that is presently teaching us techniques involved in building an online store, we are just starting with uploading files (images to be exact) but we are storing them directly into the database (which I don’t really think is the best option)

So yes, your url does make sense after reading through it.

Can anyone point me in the right direction of a tutorial or something of the like?

I would use the database to store the image info (file path/name, alt, title…etc). I would use a directory structure to store the actual image files. You should check out an image manipulation library so you can re-size the images (if necessary). I use imageGD but there are several others available.

That is what I would like to do, but I’m not 100% sure how to exactly go about doing this. I have been looking for examples or tutorials.

Sorry i’m on vacation so my internet connection time is somewhat erratic atm.

So; using that page, you can get the images to your webspace, which is a good start.

Add a field to your user table for picture (or… whatever you want to call it, really).

You can, if you want, create a selectbox based off of the directory tree; It will be subject to the filename though, so no descriptive titles.

A simple database table can be used, but somewhat precludes the FTP option.

So my next question is… What do you want to present to the user for selection?

At this point, you’ve got a collection of unchecked, unverified images of various sizes uploaded by your users.

Hi Star,

No Worries.

I was planning to have it set so that they could only upload an image of a specific dimension say 100 x 100 and then have a dropdown for selection.

Loading the names from a directory is relatively straightforward;

Next Lesson

Keep in mind that the readdir command will also return . and …, which should be skipped. (See Example 2 on that page). You may also want to strip out the file extensions from the file names ( $filename = array_shift(explode(‘.’,$filename)); )

Thanks Star,

I’ll give this a go this weekend and see how badly I break the page I make o_0;; LOL