I have some code which checks for a file and if exists then loops round with a numeric suffix.
This worked great testing on my local machine using c:\ drive, but now I have moved it my server and am calling a mapped drive called k:\ - all I changed in the code was c:\ to k:\ . Now I get the error:
Warning: copy(K:\IT\Letters\Letter.doc): failed to open stream: No such file or directory in C:\Inetpub\ on line 61
Then the system opens the template file, majes changes and cant't save it as it is read only. I thought maybe its becuase the server is calling a netowkr drive so I gave the server the same mapped drive as the clients.
My code:
This worked great testing on my local machine using c:\ drive, but now I have moved it my server and am calling a mapped drive called k:\ - all I changed in the code was c:\ to k:\ . Now I get the error:
Warning: copy(K:\IT\Letters\Letter.doc): failed to open stream: No such file or directory in C:\Inetpub\ on line 61
Then the system opens the template file, majes changes and cant't save it as it is read only. I thought maybe its becuase the server is calling a netowkr drive so I gave the server the same mapped drive as the clients.
My code:
Code:
<?php
$outpath = "K:\\IT\\letters\\";
$letter_dir = "K:\\IT\\letters\\";
// (connect to the database)
$odbc_dsn = "timeandfees_db";
$odbc_userid = "";
$odbc_password = "";
//$query = "SELECT ClientKey,CoyName FROM clients WHERE ClientKey like 'AC%' ORDER BY ClientKey ;";
$query = "SELECT * FROM qryclientsData WHERE ClientKey like '" . $_POST['custname'] . "' ORDER BY ClientKey ;";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
$num = odbc_num_rows($odbc_db,$query);
$path = "K:\\IT\\Letters\\Letter.doc";
if( !file_exists( $letter_dir . "Letter.doc" ) ) //if there isn't a $outpath\letter.doc we can just name our output that
{
$output = $letter_dir . "Letter.doc";
copy( $path,$output );
}
else //find the next name that we can use, name our output that
{
$i = 1;
while( file_exists( $letter_dir . "Letter$i.doc" ) ) $i++;
$output = $letter_dir . "Letter$i.doc";
copy( $path,$output );
echo "<p>Filename is $output</p>";
}