我试图使用POST方法上传文件(图像),但是php给我一个错误变量'f1'消息。
错误-
注意:未定义的索引:第154行的C:\ xampp \ htdocs \ webProject \ edit-profile.php中的f1
- 注意:未定义的索引:第158行的C:\ xampp \ htdocs \ webProject \ edit-profile.php中的f1
我试图更改名称并重写代码
<form name="form1" method="post">
<div class="form-group">
<label for="exampleFormControlFile1">Select a custom profile picture</label>
<input type="file" class="form-control-file" name ="f1" >
<input type ="submit" class="form-control-submit" name="submit1" value="Upload">
</div>
</form>
<?php
if(isset($_POST["submit1"]))
{
$tm=md5(time());
$fnm=$_FILES["f1"]["name"];
$dst="./images/".$tm.$fnm;
$dst1="images/".$tm.$fnm;
move_uploaded_file($_FILES["f1"]["tmp_name"],$dst);
$res2=mysqli_query($link,"SELECT * FROM image WHERE uid = $_SESSION[uid]");
$row2 = mysqli_fetch_array($res2);
if(empty($row2["image"])){
mysqli_query($link,"INSERT INTO image values('$_SESSION[uid]','$dst1')");
}else{
mysqli_query($link,"UPDATE image SET image= '$dst1' WHERE uid = '$_SESSION[uid]' ");
}
}
?>