0

I have a problem that i just quite do not understand at all. I have this uploading script that always return Notice: Undefined index: uploadPDF in xxxxx

I've made sure that the form has the enctype="multipart/form-data" <form action="" method="POST" enctype="multipart/form-data">

The field also has the same name that i ask for in the code <input name="uploadPDF" size="100" type="file" title=""/>

When i try to echo $_POST['uploadPDF'] i actually get the filename in question. But when i try to var_dump the following $_FILES['uploadPDF']['name'] i get the undefined index error.

I really cant see what the problems is. I'm running on a inhouse IIS server.

Debug information:

This is the "debug" i try to do:

echo $_POST['uploadPDF']."<br />";
$filename = $_FILES['uploadPDF']['name'];
var_dump($filename);
echo "<br />";
var_dump($_FILES);

This is the output i get:

TEST PDF PORTAL V3.pdf
Notice: Undefined index: uploadPDF in C:\inetpub\myfolder\V4\admin\addRoutine.php on line 29 
NULL 
array(0) { }
Oleaha
  • 130
  • 1
  • 2
  • 10

4 Answers4

1

When you upload file, you should use $_FILES['file_name'] not $_POST['file_name'] that is because, the file information is stored in the $_FILES arrays, since you have named your input type to 'file'

So, I would suggest

Changing

echo $_POST['uploadPDF'];

to

echo $_FILES['uploadPDF'];

samayo
  • 16,163
  • 12
  • 91
  • 106
  • The reason i use $_POST in my first debug is to see if the index 'uploadPDF' actually exists, and it does. When i try to do the same only with $_FILE i get the undefined index 'uploadPDF'. So, i verified that the index exists with $_POST, but the $_FILES function wont take it... – Oleaha May 28 '13 at 13:07
  • Well, you could just use `if($_POST)` then `var_dump($_POST)` I don't understand your question clearly, you have even wrote `$_FILE` and I don't know what it does – samayo May 28 '13 at 13:13
  • The problem is that $_FILES['uploadPDF'] returns undefined index, right? So that says me that there is a problem with the form field that i've called uploadPDF, since $_FILED['uploadPDF'] returns undefined index. To check if the form field is wrong i try to echo out the POST information, since this returns a value i know that there is no problem with the form field since i can get the value with POST, but not with FILE. – Oleaha May 28 '13 at 13:22
  • @Oleaha Can you post your file upload script so, I can have a look at it? – samayo May 28 '13 at 13:23
1

Your form as you wrote it has no action specified.

 ( <form action="" method="POST" enctype="multipart/form-data"> )

You need the asign "path_to_yourform.php" as your form action.

Gimmy
  • 3,781
  • 2
  • 18
  • 27
0

You better write it like this:

echo $_POST['uploadPDF']."<br />";
    $filename = $_FILES['uploadPDF']['name'];       
    echo var_dump($filename)."<br />";
Gimmy
  • 3,781
  • 2
  • 18
  • 27
  • It gives the same output and is only there for debug information, not to be rude but i don't understand how this helps me :) I've stripped down the script so i know that the $_FILES wont find the index, but $_POST do... – Oleaha May 28 '13 at 13:09
0

Well, this is quite embarrassing, one of the other guys working on this had left a <form action="" method="post"> in one of the included files in the project. Since this form tag was before my form tag $_FILES did not catch the index because of the missing enctype in the first form tag!

Oleaha
  • 130
  • 1
  • 2
  • 10