我正在php中创建一个注册页面。 我收到以下错误:
注意:未定义的索引:第63行的C:\ xampp \ htdocs \ project1 \ form.php中的myFile
注意:未定义的索引:第66行的C:\ xampp \ htdocs \ project1 \ form.php中的myFile
警告:getimagesize():第66行的C:\ xampp \ htdocs \ project1 \ form.php中的文件名不能为空
<form method="post" action="" enctype="multipart/form-data">
<fieldset>
<legend>Personal information</legend>
Firstname:<br />
<input type="text" name="Firstname">
<span class="error">* <?php echo $FirstnameErr; ?></span>
<br />
Lastname:<br />
<input type="text" name="Lastname">
<span class="error">* <?php echo $LastnameErr; ?></span>
<br />
Gender<br />
<input type="radio" name="Gender" value="male"> Male
<input type="radio" name="Gender" value="female"> Female
<span class="error">* <?php echo $GenderErr; ?></span>
<br />
Email:<br />
<input type="text" name="Email">
<span class="error">* <?php echo $EmailErr; ?></span>
<br />
Write about yourself:<br />
<textarea name="Bio" rows="10" cols="60">
</textarea>
<br />
Profile Picture:<br />
<input type="file" name="myFile" id="myFile">
<span class="error">* </span>
<?php echo $message; ?>
<br /><br />
</fieldset>
Username:<br />
<input type="text" name="Username">
<span class="error">* <?php echo $UsernameErr; ?></span>
<br />
Password:<br />
<input type="password" name="Password">
<span class="error">* <?php echo $PasswordErr; ?></span>
<br /><br />
<input type="submit" name="submit" value="Submit">
</form>
我的php是:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Firstname"]))
$FirstnameErr = "Firstname is required";
else
$Firstname = test_input($_POST["Firstname"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Lastname"]))
$LastnameErr = "Lastname is required";
else
$Lastname = test_input($_POST["Lastname"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Gender"]))
$GenderErr = "Gender is required";
else
$Gender = test_input($_POST["Gender"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Email"]))
$EmailErr = "Email is required";
else {
$Email = test_input($_POST["Email"]);
if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
$EmailErr = "Invalid email format";
$Email = "";
}
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$Bio = test_input($_POST["Bio"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Username"]))
$UsernameErr = "Username is required";
else
$Username = test_input($_POST["Username"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Password"]))
$PasswordErr = "Password is required";
else
$Password = test_input($_POST["Password"]);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["myFile"])) {
$target_dir = "asset/uploads/user/" . time();
$target_file = $target_dir . basename($_FILES["myFile"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$check = getimagesize($_FILES["myFile"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
}
else {
$uploadOk = 0;
}
if (file_exists($target_file)) {
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
$uploadOk = 0;
}
if ($uploadOk == 0) {
$message = "Sorry, your file was not uploaded.<br />";
}
else {
if (move_uploaded_file($_FILES["myFile"]["tmp_name"], $target_file)) {
$result = true;
$filePath = $target_file;
}
else {
$result = false;
$filePath = $target_file;
}
}
}
}
?>
有人可以帮助我吗?
答案 0 :(得分:0)
你有一个错字。
enctype:"multipart/form-data"
:
应为=
。
由于您未正确设置属性,因此请求不是多部分且文件未包含在内。