1

How do I really know if I am passing a file to the server, via a file upload option?

i) I use a form as follows:

<form name = "someForm" id = "someForm" method = "post" action = "saveFile.php">                
    <input type = "file" name = "upload1" id = "upload1" />
    <input type = "file" name = "upload2" id = "upload2" />                     
    <input type = "file" name = "upload3" id = "upload3" />
    <input type = "submit" id = "btnSubmit" value = "Submit" />
</form>

ii) In saveFile.php, I use:

say:

echo $_FILES['upload1']["size"]; 

apart from others, but I get an Undefined index: upload1 error, but not when, I use:

echo $_POST['upload1'];  //returns filename
3
  • Can you post some more code? Where are you storing the files on the server? Windows or Linux / Unix? Commented Dec 6, 2011 at 16:20
  • Windows. Storing on the server. I need to check the size of the file, and any mention using $_FILES reports an error. Commented Dec 6, 2011 at 16:21
  • You get "Undefined index: uploadSource1" but the code above it should be looking for the index "upload1" .. Is this the exact same code generating that error? Commented Dec 6, 2011 at 16:22

3 Answers 3

9

You need to specify the <form> enctype to "multipart/form-data":

<form enctype = "multipart/form-data" name = "someForm" id = "someForm" method = "post" action = "saveFile.php">                
    <input type = "file" name = "upload1" id = "upload1" />
    <input type = "file" name = "upload2" id = "upload2" />                     
    <input type = "file" name = "upload3" id = "upload3" />
    <input type = "submit" id = "btnSubmit" value = "Submit" />
</form>
Sign up to request clarification or add additional context in comments.

Comments

4
<form name="someForm" id="someForm" method="post"
    action="saveFile.php" enctype="multipart/form-data">

Enctype is required for upload of files.

You can access them by $_FILES not $_POST, nor $_GET:

echo $_FILES['upload1']['size'];

Comments

2

Files are saved in:

print_r($_FILES); // NOT IN POST

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.