PHP error - undefined index


#1

Hello. I am trying to upload a file into my web site. From the main screen (mail_file.txt attached), when pushing the UPLOAD button, i call a function from do_upload.txt file (attached) which shold do the upload. But i get an errro UNDEFINED INDEX …
This is the line generating the errror

$fileName = basename($_FILES[“file”][“name”]);

I have tried several alternatives.

  • without BASELINE, only $_FILES[“file”][“name”]
  • $_FILES[‘file’][‘name’]
    Not working.

What could be the issue. Any tips much appreciated. the files I am using have *.php extenison.

Best regards!


#2

error


#3

Is there a way to attache txt files here, with code?


#4

Three common reasons that an index in the $_FILES array would not exist are -

  1. Your form is not valid - there are several different problems that could exist, so, posting either a link to or the html of your entire form page would allow someone to determine which if anything is wrong with the form.

  2. Uploads are not enabled on your server. You can check the output from a phpinfo() statement to find if uploads are enabled. You can also add code to read the file_uploads setting and output an error message if it is not a true value.

  3. The total size of the posted form data exceeds the post_max_size setting. In this case, both the $_FILES and $_POST arrays will be empty. This is a common condition and your form processing code needs to detect this and output an error message when it occurs. If you have determined that items #1 and #2 in this list are not causing the problem, your form processing code, after detecting that a post method form has been submitted, can just test if the $_FILES array is empty to detect this condition (you can also compare the $_SERVER[‘CONTENT_LENGTH’] - an integer, with the post_max_size setting - can be either an integer or a value using k,m,g size abbreviations.)

Once you have determined that the $_FILES array is not empty, you can reference elements in the array. You would then test the $_FILES[“file”][“error”] element to find if the upload worked without any error before using any of the uploaded file information.


#5

Examples of how to upload a file that might help you locate your errors are in the link below.
Or, just post code using the correct tags around them so we can look at all the parts that Phdr mentioned.
(Usually, it is best to create a test page with just the simple form and PHP code to test the process
then, move the working code into your full program.)

 https://www.w3schools.com/php/php_file_upload.asp