1

I am doing some simple work with uploading a file. I am ignoring error checking and exceptions at this point just to get my uploads working. I have this HTML form:

<form action='addResult.php' method='post' enctype='multipart/form-data' target='results_iFrame' onsubmit='startUpload();'>
Entry: <input type='text' id='entry' />
Stop: <input type='text' id='stop' />
Final: <input type='text' id='final' />
Chart: <input type='file' id='chart' />
<input type='submit' value='Add' /></form>

As you can see, it calls 'addResult.php' within the iFrame 'results_iFrame'. The Javascript is just for animation purposes and to tell me when things are finished. addResult.php has this code in it (along with processing the other inputs):

$upload_dir = "../img/";
$chart_loc = $upload_dir.basename($_FILES['chart']['name']);

move_uploaded_file($_FILES['chart']['tmp_name'], $chart_loc);

print_r($_FILES);

It uses the 'chart' input from the form and tries to upload it. I have the print_r() function to display some information on $_FILES, but the array is empty, thus making this fail. What could I be doing wrong?

5 Answers 5

3

When dealing with forms, the name= is used to reference items serverside, not the id=.

Just change all those id attributes to namess, and you're good to go (hopefully).

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

5 Comments

"Just change all those name attributes to ids" - other way around, surely? :)
Whoops, contradicting myself again ;)
Ah, of course - it's always something simple. I had converted this from sending information to a Javascript function that used the IDs and not Names. Thanks!
I've pulled clumps of hair so many times because of the name and id thing, so no worries.
Same here. I still missed it in this question.
1

You have to give your input elements name attributes or they don't get passed to your script. The id is used for DOM/browser/client-side use.

There might be another problem after you resolve this, but this is a good first step.

Comments

0

Try adding the name attribute to your input values like so:

<input type='file' id='chart' name="myfile"/>

Comments

0

Your inputs have no "name" attribute, only IDs.

Comments

0

You need to give your form fields name attributes

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.