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) { }

4 Answers 4

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'];

Sign up to request clarification or add additional context in comments.

4 Comments

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...
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
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 Can you post your file upload script so, I can have a look at it?
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.

Comments

0

You better write it like this:

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

1 Comment

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...
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.