我试图上传一些信息到数据库使用php,我已经能够上传图像和文字分开,但不能在一起(我的目标)。由于某些原因,图像将进入指定的文件夹,但由于某些原因,信息不会被放入数据库,并不断抛出我的“失败”else语句!我显然是新的php和帮助将不胜感激!!以下是我的php代码:
<?php
include_once 'dbh.inc.php';
session_start();
if(isset($_POST['upload'])) {
$file = $_FILES['profileup'];
$fileName = $_FILES['profileup']['name'];
$fileTmpName = $_FILES['profileup']['tmp_name'];
$fileSize = $_FILES['profileup']['size'];
$fileError = $_FILES['profileup']['error'];
$fileType = $_FILES['profileup']['type'];
$Newname = $fileName;
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)){
if ($fileError === 0){
if ($fileSize < 10000000000){
$filedest = 'postimages/'.$Newname;
$username = $_SESSION[user];
move_uploaded_file($fileTmpName, $filedest);
header("Location: ../UserProfile.php?suc");
$sql = "INSERT INTO posts (img, ext) VALUES ('$filedest', '$fileActualExt');";
$result = mysqli_query($conn, $sql);
if($result !== false) {
exit;
}else{
echo "fail";
}
}else{
echo "your file was to big";
}
}else{
echo "There was an error uploading your file";
}
}else{
echo "you cant upload files of this type";
}
}else{
header("Location: ../UserProfileSetting.php?fail");
}
?>
1条答案
按热度按时间zour9fqk1#