Error while saving csv file generated by PHP
<p>I have created below script which is saving the csv file in the same path of this script but when I am saving it to different directory, it gives me error. Can somebody please help me on this?</p>

<p>This is the error:</p>

<pre><code>Warning: fopen(/store/secure/mas/) [function.fopen]: failed to open stream: No such file or directory in /getdetails.php on line 15

Warning: fputs(): supplied argument is not a valid stream resource in /getdetails.php on line 36

Warning: fclose(): supplied argument is not a valid stream resource in /getdetails.php on line 39
</code></pre>

<p>This is the script:</p>

<pre><code>&lt;?php

$MYSQL_HOST="localhost";
$MYSQL_USERNAME="***";
$MYSQL_PASSWORD="***";
$MYSQL_DATABASE="shop";
$MYSQL_TABLE="ds_orders";
mysql_connect( "$MYSQL_HOST", "$MYSQL_USERNAME", "$MYSQL_PASSWORD" ) or die( mysql_error( ) );
mysql_select_db( "$MYSQL_DATABASE") or die( mysql_error( $conn ) );


$filename="Order_Details";
$directory = "/store/secure/mas/"; 
$csv_filename = $filename.".csv";

$fd = fopen ( "$directory" . $cvs_filename, "w"); 


$today="2009-03-17";
$disp_date="05122008";
$sql = "SELECT * FROM $MYSQL_TABLE where cDate='$today'";

$result=mysql_query($sql);
$rows=mysql_num_rows($result);
echo $rows;
if(mysql_num_rows($result)&gt;0){

$fileContent="Record ID,Discount Percent\n";
while($data=mysql_fetch_array($result))
{

$fileContent.= "".$data['oID'].",".$data['discount']."\n";
}


$fileContent=str_replace("\n\n","\n",$fileContent);
fputs($fd, $fileContent);
}

fclose($fd);
?&gt;
</code></pre>
