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.
1条回答 默认 最新
- 普通网友 2012-08-24 05:01关注
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 ?>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报