0

I have this PHP code:

if(isset($_POST["submit"])) {
    echo 'submit';
    foreach($_FILES['file_name']['name'] as $key => $value) {
        echo 'file';
        $handle = fopen($_FILES['file_name']['tmp_name'][$key], "r");
        fgetcsv($handle);

        //then loop through each row
        while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            echo 'DATA: '.$data[0].'<br>';
            //and insert the data
            /*$stmt = $pdo_conn->prepare("INSERT into customer2 (industry, company, address1, town, postcode, county, phone, forename, contact_position) values (:industry, :company, :address1, :town, :postcode, :county, :phone, :forename, :contact_position) ");
            $stmt->execute(array(':industry' => $data[0], 
            ':company' => $data[1], 
            ':address1' => $data[2], 
            ':town' => $data[3], 
            ':postcode' => $data[4], 
            ':county' => $data[5], 
            ':phone' => $data[8], 
            ':forename' => $data[13], 
            ':contact_position' => $data[14] ));*/

            /*$sql="INSERT into customer2 (industry, company, address1, town, postcode, county, phone, forename, contact_position) values ('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$data[4]."', '".$data[5]."', '".$data[8]."', '".$data[13]."', '".$data[14]."'); ";
            $rs=mysql_query($sql,$conn) or die(mysql_error());*/
        }
    }
}

that runs on form submit, my form looks like:

<form method="post" action="upload_records" enctype="multipart/form-data">
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><input type="file" name="file_name" multiple="multiple" /></td>
  </tr>
  <tr>
    <td colspan="2" align="right"><input type="submit" name="submit" value="Upload" /></td>
  </tr>
</table>
</form>

when i submit the form, i see the word submit but even though a file has been chosen, nothing else is being displayed below this

i can see the file being uploaded when using chrome (showing the percentage in the bottom status bar)

3
  • do a var_dump($_FILES). confirm that you actually have multiple files in there. You MIGHT have to name the file field file_name[] instead, to tell PHP to expect multiple separate submissions under that name. Commented Jan 13, 2015 at 18:14
  • var dump is showing: array(1) { ["file_name"]=> array(5) { ["name"]=> string(17) "export_chunk1.csv" ["type"]=> string(24) "application/vnd.ms-excel" ["tmp_name"]=> string(14) "/tmp/phpooQMEL" ["error"]=> int(0) ["size"]=> int(2410) } } Commented Jan 13, 2015 at 19:58
  • so. yep. one single file being submitted. change to file_name[] (add the []) and see if that helps. Commented Jan 13, 2015 at 19:59

1 Answer 1

4

Have you checked your server's filesize limits? You can try increasing them with:

ini_set('memory_limit', '96M');
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');

Eh, I wanted to post it as a comment but need more points soo, that's my lame attempt at making my question as an answer.

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

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.