I'm tring to read in a file from a remote computer and store it on my filesystem with a reference in the Database.
But When Itry to upload from anywhere but my server it tries to look on the server for the file and of course cannot find it.
Errors:
Warning: fopen(X:\BP Import list.xls): failed to open stream: No such file or directory in c:\inetpub\wwwroot\sparktrial\lib\fileopen.inc.php on line 16
Warning: filesize(): Stat failed for X:\BP Import list.xls (errno=2 - No such file or directory) in c:\inetpub\wwwroot\sparktrial\lib\fileopen.inc.php on line 19
Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\sparktrial\lib\fileopen.inc.php on line 19
Warning: fclose(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\sparktrial\lib\fileopen.inc.php on line 20
CODE:
function fileopen($file, $use_include_path = 0){
$file = stripslashes($file);
$handle = fopen("$file", "rb", $use_include_path); //OPEN THE FILE
echo $handle; //DEBUG
$ctype = mime_content_type('$file');
$contents = fread($handle, filesize($file)); //READ IN THE FILE
fclose($handle); //CLOSE THE FILE
//echo $contents; //DEBUG TO SEE IF WE HAVE THE FILE
//return($contents);
$data = unpack("Hhex", $contents);
$query = "SELECT FROM files";
$result = mssql_query( $query );
$count = mssql_num_rows( $result);
$id = $count;
$file_code = "CO0" . $count;
$filename = ltrim(strrchr($file,'\\'),'\\');
// writing out the file to a new file on the web server.
if (!file_exists("..\..\files\$filename")) {
$handle = fopen("..\\..\\files\\" . $file_code, 'x');
fwrite($handle,$contents);
fclose($handle);
}
$submit = "INSERT into files (file_id,name,data,content_type,file_code)values" .
"($id,\"$filename\", 0x".$data['hex'].",\"$ctype\", \"$file_code\")";
//echo $submit;
mssql_query($submit);
}