我想用PHP上传图像文件。如何将POST数据传递到另一个文件中的PHP函数,单击提交按钮时将执行该数据...
形式如下:
<!-- edit users profile picture -->
<form method="post" action="edit.php" name="user_edit_profile_picture">
<input type="file" name="profil_slika" id="profil_slika">
<input type="submit" name="user_edit_submit_profile_picture">
<?php
$con = mysqli_connect("localhost","root","","login");
$q = mysqli_query($con,"SELECT * FROM users WHERE user_name = '".$_SESSION['user_name']."'");
while($row = mysqli_fetch_assoc($q)){
echo $row['user_name'];
if($row['image'] == ""){
echo "<img width='100' height='100' src='profile_pictures/default_user.png' alt='Default Profile Pic'>";
} else {
echo "<img width='100' height='100' src='profile_pictures/".$row['image']."' alt='Profile Pic'>";
}
echo "<br>";
}
?>
</form>
这是另一个具有功能的PHP文件:
elseif(isset($_POST["user_edit_submit_profile_picture"])) {
$this->editUserPicture($_POST['profil_slika']);
}
和功能体:
public function editUserPicture($profilimage){
$slika = $_FILES[$profilimage]['tmp_name'];
echo $slika;
move_uploaded_file($_FILES[$profilimage]['tmp_name'],"profile_pictures/".$_FILES[$profilimage]['name']);
}
当前,当我单击提交时,我收到此错误消息:
注意:第55行的C:\ xampp \ htdocs \ advanced \ classes \ Login.php中的未定义索引:image.jpg
先感谢您!
更改此:
$this->editUserPicture($_POST['profil_slika']);
对此:
$this->editUserPicture('profil_slika');
并且还添加enctype="multipart/form-data"
了HTML的属性<form>
。
其原因是,profil_slika
将不会被传递到$_POST
阵列。它将$_FILES
与key一起位于数组中profil_slika
。换句话说,你需要使用的关键$_FILES
阵列是对name
的HTML的input
,你不需要使用$_POST
的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句