仅上传图片jpg,jpeg,bmp,gif和png。如何在此代码中编写代码

时间:2017-07-08 10:06:58

标签: c#

if(FileUpload1.HasFile) {     string extension = System.IO.Path.GetExtension(FileUpload1.FileName);

if (extension == ".jpg")
{
    FileUpload1.SaveAs("yourpath" + FileUpload1.FileName);

}
else
{
Response.Write("Only .Jpg allowed");
}

}

1 个答案:

答案 0 :(得分:-3)

请尝试以下操作:

require("Password.php");

ini_set('display_errors', 'On');
$mysqli = new mysqli("localhost", "id2147309_javaprojekt123", "javaprojekt321", "id2147309_javaprojekt");

if($mysqli->connect_errno){
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if(isset($_POST["name"]) && isset($_POST["surname"]) && isset($_POST["login"]) && isset($_POST["password"]) && isset($_POST["groupNumber"]) && isset($_POST["indexNumber"]))
{
$name = $_POST["name"];
$surname= $_POST["surname"];
$login = $_POST["login"];
$password = $_POST["password"];
$groupNumber = $_POST["groupNumber"];
$indexNumber = $_POST["indexNumber"];
}

function registerUser(){
    global $mysqli, $name, $surname, $login, $password, $groupNumber, $indexNumber;
    $passwordHash = password_hash($password, PASSWORD_DEFAULT);
    $stmt = $mysqli->prepare("INSERT INTO user (name, surname, login, password, groupNumber, indexNumber) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("ssssss", $name, $surname, $login, $passwordHash, $groupNumber, $indexNumber);
    $stmt->execute();
    $stmt->close(); 
}



function usernameAvailable(){
    global $mysqli, $login, $count;
    $sql = "SELECT * FROM users WHERE login = ?";
    if($stmt = $mysqli->prepare($sql)){
    $stmt->bind_param("s", $login);
    $stmt->execute();
    $stmt->store_result();
    $count = $stmt->num_rows;
    $stmt->close();
    }
    if($count < 1){
        return true;
    }
    else 
        return false;
}
    $response = "false";

if(usernameAvailable()){
    registerUser();
    $response = "true";
}echo json_encode($response);
$mysqli->close();