我想用PHP上傳圖像文件。我怎樣才能POST數據傳遞到另一個文件中的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']);
}
目前我得到這個
注意:當我點擊提交錯誤信息未定義指數:image.jpg的在C:\ XAMPP \ htdocs中\高級\ \類上的login.php在線55
預先感謝您!
有趣,但它工作:)謝謝。 – Volkan