I’m attempting to upload a file and then move it into an Access database. The filed is named ‘Attachment’ and has the Attachment property. It works fine in Access.
It uploads onto the server fide but I cannot get it to insert into the database.
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "File name: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
move_uploaded_file($_FILES["file"]["tmp_name"], "C:/AccessBackEnds/LiveDesk/Uploads/" . $_FILES["file"]["name"]);
echo "Stored in: LiveDesk/Uploads/";
}
$file = "C:/AccessBackEnds/LiveDesk/Uploads/" . $_FILES["file"]["name"];
$db = realpath('C:\AccessBackEnds\LiveDesk\LiveDeskBackEnd.accdb');
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$db",'','') or die ("Unable to connect to server");
$input="INSERT INTO CallTracker (Attachment)
VALUES
(file($file))";
$rs=odbc_exec($conn,$input);
if (!$rs)
{
die('Error: ' . mysql_error());
}
?>
The error is Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'file(C:/AccessBackEnds/LiveDesk/Uploads/CdpPacket.inf)'., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\test\upload_file.php on line 26
Any help is appreciated, thanks.
PHP uses a temporary filename to store uploads, which is NOT the name of the file on the client's machine.
$file = "C:/AccessBackEnds/LiveDesk/Uploads/" . $_FILES["file"]["name"];
^^^^^^^^
that should be ['tmp_name']
instead.
As well... does Ms Access have a file()
function? I can't find any indication that it does.