Search code examples
phpsql-servercsvfopenfgetcsv

Importing large size of CSV to SQL got this Warning: fopen(): Filename cannot be empty


I tried to import multiple rows of CSV to SQL and this code is working with few number of rows only (ex. 75 rows) to import and it succeed but when I tried to import multiple number of rows (ex. 700000 rows) in SQL this appears.

enter image description here

if(($handle = fopen($_FILES['file']['tmp_name'], 'r')) !== false)
    {
    $header = fgetcsv($handle);
    while(($data = fgetcsv($handle)) !== false){
    $sql = "INSERT into mansfield_barcode.dbo.".$_POST['uploadSName']." values('".implode("','", $data)."')";
    $result = mssql_query($sql);
    unset($data);

    if(! $result ){
    echo "<script type=\"text/javascript\">
    alert(\"Invalid File:Please Upload CSV File.\");
    window.location = \"sku.php\"
    </script>";
    }
    }
    fclose($handle);
    echo "<script type=\"text/javascript\">
    alert(\"CSV File has been successfully Imported.\");
    window.location = \"sku.php\"
    </script>";
    }

Solution

  • Resolved the issue by changing the

    post_max_size = 64M
    upload_max_filesize = 64M
    

    in php.ini

    Thanks JDpawar