注意:未定义的索引:($ _FILES)

时间:2016-08-26 03:57:04

标签: php mysql

关于同样的错误有多个问题[重复],但我找不到任何解决方案。我试图在我的本地目录中保存图像,但“未定义的索引”不断出现。我是php和堆栈溢出的菜鸟。我非常感谢你的任何帮助。

HTML:

<form method="post" action="process.php" enctype="multipart/form-data">
  <fieldset>
    <div class="col-xs-12 col-sm-push-5 image-div form-control">
      <div class="input-margin">
        <input type="file" name="imagenIngreso" class="filestyle" onchange="readURL(this);" data-buttonText="Subir Imagen" data-buttonName="btn-primary" data-size="nr" data-buttonBefore="false">
      </div>
      <div>
        <img class="image-preview" id="blah" src=""/>
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 submit-button">
      <button type="submit" class="btn btn-primary btn-block" name="submit" value="ingreso">Ingresar</button>
    </div>
  </fieldset>
</form>

PHP:

 // Previous Validations
 else if($_POST['submit'] == 'ingreso') {
    $fileName = $_FILES['imagenIngreso']['name']; // Line throwing error
    $uploadDirectory = "images/uploadedImages/Ingresos/";
    if($uploadedFileName!='') {
      $targetPath=time().$uploadedFileName;
      if(move_uploaded_file($_FILES['imagenIngreso']['tmp_name'], $uploadDirectory.$targetPath)) {    
        $queryIngresos = "INSERT INTO ingresos (fechaIngreso, responsable, proyecto, items, imagePath) VALUES (STR_TO_DATE('$fechaEgreso','%d/%m/%Y'), '$responsable', '$proyectoIngreso', '$itemsArray', '$targetPath')"; 
        if(!mysqli_query($con, $queryEgresos)) {
          echo "Error while uploading file";
          die('Error :'.mysqli_error($con));
        } else {
          echo 'Upload done';
          exit();
        }

      }

    }

1 个答案:

答案 0 :(得分:0)

您还可以使用可用的错误代码找到您获得的错误。 把它放一试试试。

<?php
if($_FILES['userfile']['error']) {
  // handle the error
} else {
  // process
}
?>