Swanny86uk Posted August 31, 2007 Share Posted August 31, 2007 Hey, I have recently spent hours adding a register / login script to my website. Since i'm a newbie to PhP it took me alot of time and coffee to get it sorted. So here I am at another roadblock. I want to be able to let my logged in users upload pictures (JPG's and relatively small file sizes) and then these pictures to appear on their own profile page. I found an upload script which lets the users upload pictures onto a folder on my webserver, but not transfer these uploaded images to the profile of the user who uploaded them .... confused ?! I am ! :-\ I recieved some help from another forum along the lines of ; "You would have to check who is logged on, insert data in the the mysql db like image path. Then in their profiles query the db and check the image for the profile." Due to my 'newbishness' this made absolutely no sense to me. If anyone could explain this to me or any other way/solution I would be very grateful ... and hey ... maybe even save on this weeks coffee bill ! Thanks Alot Marc Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted August 31, 2007 Share Posted August 31, 2007 Cant you store their ID number as a session when they login and then whenever they upload an image, insert the image into a table along with the users ID number. Then you can grab the users images from that table. Does that help? Quote Link to comment Share on other sites More sharing options...
Timma Posted August 31, 2007 Share Posted August 31, 2007 How about, a folder is automatically created for each new user, and when they upload an image, it is put in there, renamed to profilepic.png or whatever and then set as their picture? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 31, 2007 Share Posted August 31, 2007 How is your login script working? MySQL, FlatFile etc ? probably the "simplest" way would be using the UsersID or Username (whatever is uniqe) then move the file to the "profile images" folder and rename it to that unique name/id .jpg Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 The upload script u have should be like the following example: $userid = 10; //normally u should have got the ID of the user when he logged in $filename = $_FILES['upload']['name']; if(move_uploaded_file($_FILES['upload']['tmp_name'], $filename)){ //the following part inserts the filename of the uploaded file to the db $query = mysql_query("UPDATE users SET image='$filename' WHERE id='$userid'"); echo 'The file was successfully uploaded'; } else{ echo 'An error occured. Try again later'; } Normaly u should have an upload form (with enctype=multipart/formdata) in which the user browses for the file and submits. When the form is submited, u use move_uploaded_file() and the files superglobal to upload the file in a directory. If it is uploaded also the mysql query is run to update the user profile. Hope its clear. 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.