buddy Posted October 13, 2010 Share Posted October 13, 2010 Long time lurker, first time poster here. I am having a problem with a multiple file uploader form I am trying to build. I am using the CodeIgniter framework, but I believe my problem is with the form itself. Here is the form: <form action="http://localhost/show/submit" id="sendfiles" method="post" name="sendfiles" enctype="multipart/form-data"> <input type="hidden" name="doup" value="1" /> <input type="file" name="userfile1" value="" id="userfile1" size="20" /> <br /> <input type="file" name="userfile2" value="" id="userfile2" size="20" /> <br /> <input type="file" name="userfile3" value="" id="userfile3" size="20" /> <br /> <input type="submit" name="submit_btn" value="Upload" /> </form> The form is being passed to this function: if(empty($_POST['doup'])){ foreach($_REQUEST as $k => $v) print ">>> $k : $v <br />"; $data['form_open'] = form_open_multipart(uri_string(), array( 'id' => 'sendfiles', 'method' => 'post', 'name' => 'sendfiles' )); $data['form_flag'] = form_hidden('doup', '1'); $data['file1'] = form_input(array( 'id' => 'userfile1', 'name' => 'userfile1', 'size' => '20', 'type' => 'file', )); $data['file2'] = form_input(array( 'id' => 'userfile2', 'name' => 'userfile2', 'size' => '20', 'type' => 'file', )); $data['file3'] = form_input(array( 'id' => 'userfile3', 'name' => 'userfile3', 'size' => '20', 'type' => 'file', )); $data['form_submit'] = form_submit('submit_btn', 'Upload'); $data['form_close'] = form_close(); $this->load->view('show/submit', $data); } else { $config['allowed_types'] = 'mp3'; $config['max_size'] = '10240'; $config['upload_path'] = $this->config->item('file_upload_path'); $uploaded_files = array(); for($nona=1; $nona<4; $nona++){ if (strlen($_FILES['userfile'.$nona]['tmp_name']) <=0){ echo "tempname$nona failed"; continue; } //print "------ USERFILE $nona ------ <br />"; //print sizeof($_FILES['userfile'.$nona])."<br />"; //foreach ($_FILES['userfile'.$nona] as $k => $v){ // print "$k : $v <br />"; //} $this->upload->initialize($config); $upload = $this->upload->do_upload('userfile'.$nona); if (!$upload){ $form_errors = array('form_errors' => $this->upload->display_errors()); $this->load->view('show/submit', $form_errors); break; } else { $data = array('upload_data' => $this->upload->data()); $data = $data['upload_data']; $fp = $data['full_path']; $filename = strtolower(random_string('numeric', 16) . $data['file_ext']); $rel_path = 'show/submissons/uploaded/'; $path = $this->config->item('media_root_path') . $rel_path; exec('mkdir -p ' . $path , $a1, $r1); exec('mv ' . $fp . ' ' . $path . $filename, $a2, $r2); array_push($uploaded_files, $path . $filename); } } $this->session->set_flashdata('img_data',implode("||", $uploaded_files)); // redirect("show/submit_info"); } The problem is this: When I choose only one file to upload, it works. I can choose any of the 3 inputs and it works great. But as soon as I try to choose 2 or more files, the form fails to post. When I press submit, the page simply reloads and none of the form variables get posted. I have checked settings in php.ini and tried building and rebuilding this form. I'm hoping someone here can provide some insight into what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/215755-multipart-form-wont-post-when-multiple-typeinput-elements-are-defined/ Share on other sites More sharing options...
rwwd Posted October 13, 2010 Share Posted October 13, 2010 Have you actually tried to echo the $_FILES array as well as the $_POST array after the submit button has been actioned? I also strongly recommend you NOT using the $_REQUEST global, as this reveals a lot of information about your site; though for dev resons, it is useful, but certainly not for production server release. Not too sure on the form's action either, surely you would like to point it to a file, but I have not tried your way before so FAIK it might default to a file called index or something if there is just a file path there... Rw Quote Link to comment https://forums.phpfreaks.com/topic/215755-multipart-form-wont-post-when-multiple-typeinput-elements-are-defined/#findComment-1121692 Share on other sites More sharing options...
buddy Posted October 13, 2010 Author Share Posted October 13, 2010 Hey, thanks for the reply. I have tried echoing both $_POST and $FILES upon submission, but the form never seems to make it that far.. My use of $_REQUEST was in the hopes of finding some of my form data had been posted back, but it never lists any of the info when it fails. As for the action, it is permissible with the code igniter framework. However, I don't think I'm even making it this far. When I select multiple files, it's like the form never posts at all. Even though I've hit submit, the line: if(empty($_POST['doup'])){ seems to be returning false because the form simply refreshes and no action is taken. However, if I choose only one file, the upload and file move proceed perfectly. Is there an apache swithc I need to flip to allow multiple type=file fields in my form? Quote Link to comment https://forums.phpfreaks.com/topic/215755-multipart-form-wont-post-when-multiple-typeinput-elements-are-defined/#findComment-1121812 Share on other sites More sharing options...
premiso Posted October 13, 2010 Share Posted October 13, 2010 Chances are you have reached the POST and or UPLOAD limits set in the php.ini Take a look at these variables in your php.ini: post_max_size = 8M upload_max_filesize = 2M max_file_uploads = 20 The M means megabytes. Change that to a suitable number for what you think an upper limit should be on the items you want to upload. Also check the file uploads, make sure it is > 2 Quote Link to comment https://forums.phpfreaks.com/topic/215755-multipart-form-wont-post-when-multiple-typeinput-elements-are-defined/#findComment-1121851 Share on other sites More sharing options...
buddy Posted October 13, 2010 Author Share Posted October 13, 2010 Yes, that was it...thanks Premiso! I had edited the upload_max_filesize and max_file_uploads variables but did not know about post_max_size. Thanks again everyone. Quote Link to comment https://forums.phpfreaks.com/topic/215755-multipart-form-wont-post-when-multiple-typeinput-elements-are-defined/#findComment-1121863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.