php error "filename cannot be empty, expects parameter 1 to be resource, supplied argument is not a valid stream"
<p>I'm trying to use the following code to upload a csv file usually around 20,000 data into sql server database. </p>

<p>This code very rarely uploads successfully but usually i get the error below :</p>

<p>*<strong>*Warning: fopen() [function.fopen]: Filename cannot be empty in C:\Inetpub\wwwroot\file.php on line 37</strong></p>

<p><strong>Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\file.php on line 39</strong></p>

<p><strong>Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\file.php on line 40**</strong></p>

<pre><code>&lt;?php
if(isset($_POST['SUBMIT'])) 
{
$filename =$_FILES['sel_file']['name'];
$checkextension = explode(".",$filename);

if($checkextension[1]) == "csv")
{
$filename1 = $_FILES['sel_file']['tmp_name'];
$handle=fopen($filename1,"r");
while($data=fgetcsv($handle,1000000)) { $records = count($data);  } 
fclose($handle);
if($records==15) {
$handle=fopen($filename1,"r");
while (($data = fgetcsv($handle, 1000000,",")) !== FALSE) {
$sqlquery = "INSERT into dataupload (date, field1, field2,
field3, field4, field5, field6, field7, field8, field9,
 field10, field11, field12, field13, field14, field15)
 values ('$data[0]','$data[1]', '$data[2]','$data[3]','$data[4]', 
'$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]',
 '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]')";
 mssql_query($sqlquery); }
 fclose($handle);
 echo "imported successfuly"; } else { echo "--sorry it is not csv file..."; }
  } }
</code></pre>
