Click here to Skip to main content
14,698,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get an "undefined index error" each time i try to upload documents.

I am looking to upload multiple documents through a form and submit it to sengrid as an attachment. This is my code snippet below

" $file_parts = explode('.',$_FILES['fileupload'][$file_name]); "

What I have tried:

if(isset($_FILES['fileupload'])){
  $errors= array();
  $file_name = $_FILES['fileupload']['name'];
  $file_size =$_FILES['fileupload']['size'];
  $file_tmp = $_FILES['fileupload']['tmp_name'];
  $file_type = $_FILES['fileupload']['type'];
  $file_parts = explode('.',$_FILES['fileupload'][$file_name]);
  $file_ext = strtolower(end($file_parts));
    
    
  $expensions= array("pdf","doc","docx");// Define with files are accepted
                                  
  $OriginalFilename = $FinalFilename = preg_replace('`[^a-z0-9 _.]`i','',$_FILES['fileupload']['name']); 

  $FileCounter = 1; 



..............}
Posted
Updated 6-Aug-20 3:10am
v3

1 solution

You need to understand what this error means to solve for it. Here: Notice: Undefined Index error in PHP[^]

Quote:
While working in PHP, you will come across two methods called $_POST and $_GET. These methods are used for obtaining values from the user through a form. When using them, you might encounter an error called “Notice: Undefined Index”.

This error means that within your code, there is a variable or constant that has no value assigned to it. But you may be trying to use the values obtained through the user form in your PHP code.

The error can be avoided by using the isset() function. This function will check whether the index variables are assigned a value or not, before using them.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900