我想更新默认个人资料照片 我的表格是
<div class="profile-photo-container">
<img src="images/profile-photo.jpg" alt="Profile Photo" class="img-responsive" />
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=post enctype="multipart/form-data" >
<input type=hidden name="MAX_FILE_SIZE" value="1000000" />
<input type=submit value=submit />
</form>
显示代码是
上传代码来自此link
答案 0 :(得分:0)
我没有看到任何PHP代码,但这里是我使用的代码:请注意这是非常基本的,检查安全性等。 创建表单:
<form action="handler.php" method='post' enctype="multipart/form-data">
Profile Description : <input type="text" name="description"/>
<input type="file" name="profile" value="profile" accept="image/png"/>
<input type="submit" name="submit" value="Upload"/>
</form>
handler.php
$name= $_FILES['profile']['name'];
$tmp_name= $_FILES['profile']['tmp_name'];
$submitbutton= $_POST['submit'];
$position= strpos($profile, ".");
$fileextension= substr($name, $position + 1);
$fileextension= strtolower($fileextension);
$description=$_POST['description'];
if (isset($name)) {
$path= 'path/to-your-upload/folder/';
if (!empty($name)){
if (move_uploaded_file($tmp_name, $path.$name)) {
echo 'Uploaded to Server !';
//connection to database
$conn= mysqli_connect($host, $user, $password);
if (!$conn)
{
die ('Could not connect:' . mysqli_error($conn));
}
mysqli_select_db($conn, $dbase);
if(!empty($description)){
mysqli_query($conn, "UPDATE $table SET description= '".$description."', profile_pic='".$name."' WHERE user_id='".$_SESSION['user_id']."' AND user_email='".$_SESSION['user_email']."' ");
}
mysqli_close($conn);