views:

320

answers:

1

I've looked through the Related Questions section and I can't find an answer to this. I'm using PHP + Jquery. I added <input type='file' name='file[]' size='20 />' dynamically, using Jquery. However, when I Post the data, and use print_r($_POST);, I get the other elements that were there before I dynamically added the Jquery Code, but not the file elements.

Can someone help? Thanks in advance.

[EDIT] Code added:

$(".btn_add").click(function () {
$("#file_stage").before("<tr><td>Primary <input type='radio' name='primary' value='0' /></td><td>File: <input type='file' name='file[]' size='20' /></td></tr>");

});

[EDIT] Link to Fixee: http://fixee.org/paste/uox0hqy/

+2  A: 

did you used an enctype while creating the form?

<form action="http://example.com/" enctype="multipart/form-data" method="post">
    <!-- your input fields -->
</form>

please note that you can access files from forms via $_FILES not via $_POST

print_r($_FILES);

EDIT (code recieved): you should add the enctype to the html form using input="file" fields (http://fixee.org/paste/uox0hqy/ - line 80)

<form method="post" action="<?php echo base_url();?>admin/content/albums/" id="new_album" enctype="multipart/form-data" name="new_album">
Tim
I added the enctype, however, my predicament hasn't changed. I've also tried $_FILES, as you suggested. I just get an array(), nothing else.
lucha libre
alright seems like trial and error doens't work here. can you post all the html/js code?
Tim
I did in the main question. I'll do a pastebin as well.
lucha libre
I did what you requested, but no dice. I have a question though. When I check the page source, I don't see the html code for the input file. However, I see the html file upload element, that is, when I view it in my browser. Why? Thanks.
lucha libre
depends on your browser. I recommend using Firefox and Firebug (Addon)
Tim
In addition it seems like you're using a framework. Some frameworks clean gobal vars like POST and FILES. You may check the frameworks manual about this.
Tim
I'm using codeigniter, plus I use Firefox. Sigh, I'll keep working on it, I'll see what happens. I'll try to report it when I find the answer.
lucha libre
When using codeigniter i highly recommend using the file upload class http://codeigniter.com/user_guide/libraries/file_uploading.html
Tim