Jump to content

Retrieving and Showing Uploaded Images


Swanny86uk

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.