开发者

Why is my PHP upload script not working?

开发者 https://www.devze.com 2023-02-13 20:02 出处:网络
I am doing some simple work with uploading a file.I am ignoring erro开发者_如何学JAVAr checking and exceptions at this point just to get my uploads working.I have this HTML form:

I am doing some simple work with uploading a file. I am ignoring erro开发者_如何学JAVAr 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?


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


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.


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

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


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


You need to give your form fields name attributes

0

精彩评论

暂无评论...
验证码 换一张
取 消