错误通知:未定义索引:文件未上传

问题描述

当我提交包含文件(包含png图像)的表单时,它向我返回错误通知:未定义索引:文件。我认为该图片未上传,我真的不知道为什么,它还给我带来了其他第一件事:您无法使用此扩展名上传图片,并且pdo请求的错误不能为空。

if (isset($_POST['file'])) {
  $file = $_FILES['file'];

  $fileName = $_FILES['file']['name'];
  $fileTmpName = $_FILES['file']['tmp_name'];
  $fileSize = $_FILES['file']['size'];
  $fileError = $_FILES['file']['error'];
  $fileType = $_FILES['file']['type'];

  $fileExt = explode('.',$fileName);
  $fileActualExt = strtolower(end($fileExt));

  $allowed = array('jpg','jpeg','png','gif');

  if (in_array($fileActualExt,$allowed)) {
    if ($fileError === 0) {
      if ($fileSize < 60000) {
        $fileNameNew = uniqid('',true).".".$fileActualExt;
        $fileDestination = '../img/uploads_profile/'.$fileNameNew;
        move_uploaded_file($fileTmpName,$fileDestination);
      } else {
        echo "Your file is too big";
      }
    } else {
      echo "An error happened";
    }
  } else {
    echo "You cannot upload with this extension";
  }
};

$_SESSION["user"] = $name;

$request = $pdo->prepare('INSERT INTO profil(name_user,restaurant_type,email_user,postal_user,password_user,confirm_password_user,url_img_user) VALUES(:name,:type,:email,:address,:password,:password_conf,:file)');

$request->bindValue(':name',$name);
$request->bindValue(':type',$type);
$request->bindValue(':email',$email);
$request->bindValue(':address',$address);
$request->bindValue(':password',$password);
$request->bindValue(':password_conf',$password_conf);
$request->bindValue(':file',$file);

$request->execute();

header("location: login.php");

<form action="sql_request_signup.php" method="POST">
    
                    <div class="form-flex">
                        <div class="left-form">
                            <div>
                                <label for="name">Nom du restaurant</label>
                            </div>
    
                            <div>
                                <input type="name" name="name_restaurant" placeholder="Entrez le nom du restaurant" required>
                            </div>
    
                            <div>
                                <label for="mail">Adresse email</label>
                            </div>
    
                            <div>
                                <input type="email" name="email" placeholder="Entrez votre adresse email" required>
                            </div>
    
                            <div>
                                <label for="password">Mot de passe</label>
                            </div>
    
                            <div>
                                <input type="password" name="password" placeholder="Entrez votre mot de passe" required>
                            </div>
                        </div>
    
                        <div>
                            <div>
                                <label for="type">Type de restaurant</label>
                            </div>
    
                            <div>
                                <input type="name" name="type" placeholder="Fast food,gastronomique..." required>
                            </div>
    
                            <div>
                                <label for="address">Adresse postale de l'établissement</label>
                            </div>
    
                            <div>
                                <input type="address" name="address" placeholder="Entrez votre adresse postale" required>
                            </div>
    
                            <div>
                                <label for="confirm-password">Confirmation du mot de passe</label>
                            </div>
    
                            <div>
                                <input type="password" name="password_conf" placeholder="Confirmez votre mot de passe" required>
                            </div>
                        </div>
                    </div>
    
                    <div class="image-upload">
                        <label for="password">Télécharger une photo du restaurant</label>
                    </div>
    
                    <div>
                        <input type="file" name="file" enctype="multipart/form-data"  required>
                    </div>
    
                    <input type="submit" value="Inscription" name="submit">
                </form>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...