上传用户图片

时间:2015-01-24 11:17:19

标签: php mysql upload

您好我一直想尝试上传用户图片。图像应保存在文件夹中,并且在数据库中只保存图像的链接。它

它给了我if的答案(move_uploaded_file($ _ FILES ['userfile'] ['tmp_name'],$ uploadfile))

继承我的代码:

<?php
require_once "common.php";
session_start();
$username = $_SESSION["user"];

// get userimage
$dbc = @new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
if ($dbc->connect_error) die("Database connection failed: $dbc->connect_error");
$dbc->set_charset("utf8");
$query = "SELECT userimage FROM members WHERE username = '$username'";
$result = mysqli_query($dbc, $query);
$userimagearray = mysqli_fetch_assoc($result);
$userimage = $userimagearray["userimage"];
//
//upload userimg
$imagedir = "../images/userimages/";
$uploadfile = $imagedir . basename($username);
if(isset($_POST["sendfile"])){
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Upload Worked.\n";
//Update Database Entry
$updateimage = "UPDATE members ".
    "SET userimage = '<<mysite>>/Uploaduserimage/images/userimages    /$username' ".
    "WHERE username = $username";
mysqli_query($dbc, $updateimage);


} else {
echo "Error!\n";
}
}
//

?>

0 个答案:

没有答案