-2

我正在使用 WAMP,并且我的数据库中有一个需要 ID、名称、路径照片等的表。我的 Web 应用程序中有一个文件夹,用于存储用户的所有照片。并且每个用户都可以上传他们的单张照片并将其存储在特定文件夹中,当用户登录时,与用户匹配的照片将显示在用户的主页上我使用 html 作为我的前端和 PHP 作为我的后端-结尾。如果用户决定自动更改照片,新照片将覆盖或删除用户的旧照片。在此使用什么功能?我需要你所有的建议或意见。谢谢你。

4

1 回答 1

0

这是你如何做的,一个粗略的代码。您的 html 表单

<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>

和你的 php 页面 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
?>
于 2012-08-24T05:01:29.517 回答