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.
Simple function that stores images through a specific folder of the web application and retrieve it?
Asked
Active
Viewed 259 times
-2
-
were you able to upload image when user creates the account?? – WatsMyName Aug 24 '12 at 04:44
1 Answers
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
-
Thank sir i'll try this. when i will use php's unlink will the old photo will be removed to the folder? – Augustine Frendz Aug 24 '12 at 05:06
-
@AugustineFrendz, yes use `unlink("uploads/filename.jpg")` to remove files from uploads folder. – WatsMyName Aug 24 '12 at 05:10
-
if you are using local computer, you dont have to worry about that. If the files are in remote server you can do via FTP client software. Right clicking the files on ftp client will show you direction. – WatsMyName Aug 24 '12 at 05:41
-
-
it works! thanks, how to restrict this? example max_size=10 max_height=10 max_Width=10 etc – Augustine Frendz Aug 24 '12 at 06:58