-2

I am using WAMP and i have a table in my database that needs id,name,pathphoto,and etc. I have a folder in my web application that stores all the photos of the users. And every user can upload a single photo of them and stores it in a specific folder, when users logged in, the photo that match the user will display in user's main page I am using html for my front-end and PHP for my back-end. And if the user decides to change the photo automatically the new photo will overwrite or removed the old photo of the user. What functions to use in this? I need all your suggestions or advice. Thank you.

Augustine Frendz
  • 71
  • 1
  • 1
  • 4

1 Answers1

0

Here it is how you do it, A rough code. Your html form

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

and your php page uploader.php

<?php

// Where the file is going to be placed 
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
//a destination path with filename. Make sure your uploads folder have read write permission

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

//Save user info into database along with a filename that has been uploaded, i.e. basename( $_FILES['uploadedfile']['name']

Now you have uploaded file to a folder, when user edits his profile you can delete image using php's unlink function and upload a new image as you have done above
?>
WatsMyName
  • 4,240
  • 5
  • 42
  • 73