未定义的变量:文件(多行)

时间:2018-09-03 20:53:27

标签: php mysql xampp localhost

未定义变量:文件-多行

图片部分出现错误,即$ imageName,$ imageType,$ imageSize,$ imageTmp

提交表单后,警报提示“文件类型无效” 错误来了...

此处的PHP代码-

<?php
include'includes/connect.php';

if(isset($_POST['submit'])) {
if($_POST['title']=='' or $_POST['content']=='' or $_POST['author']=='') {
    echo('<script>alert("All Fields Are Required")</script>');
    exit;
}else{
    $title = $_POST['title'];
    $author = $_POST['author'];
    $content = $_POST['content'];
    $imageName = $_FILES['image']['name'];
    $imageType = $_FILES['image']['type'];
    $imageSize = $_FILES['image']['size'];
    $imageTmp = $_FILES['image']['tmp_name'];
    $date = date('y.m.d');

    if($imageType=='image/jpeg' or $imageType=='image/jpg' or $imageType=='image/png' or $imageType=='image/gif') {
        if($image_size<=5000000) {
            move_uploaded_file($image_tmp, 'images/image_name');
        }else{
            echo('<script>alert("File size exceeds")</script>');
        }
    }else{
        echo('<script>alert("Invalid file type")</script>');
    }
    $query = "INSERT INTO blog_post ('title','author','image','content','date') VALUES ('$title','$author','$imageName','$content','$date')";
    if(mysqli_query($con,$query)) {
        echo('Inserted');
    }
    /*header("refresh:2; url=blog_post.php");*/
}
}
?>

此处连接-

<?php
$con = mysqli_connect("localhost","root","","cms");
?>

请帮助

1 个答案:

答案 0 :(得分:-1)

每个call your Cloud Function from within your app using the Firebase SDK type是由浏览器设置的,并不可靠。在这种情况下,听起来好像浏览器没有提供此功能,这就是为什么您首先收到undefined警告的原因。 manual发布的答案将是获取图像文件类型的不错选择。