Hello all,
I am completely 100% php newbie.
I have been working with asp for a while now and have been presented with the challenge of viewing a pdf with php.
I have done something similar with asp which is this:
Above code allows me to click on a pdf file and open on a browser to view contents.
Well, since our php guy is on a maternity leave (his wife had a baby) for 3 weeks and we needed to get this done,
I have been trying to re-write it in php.
So far, I am getting errors that I really don't know how to resolve.
I was wondering if someone could be kind enough to help me resolve this.
Here is my table structure.
Table name: Access database
ID autonumber
sitecode text
filesize number
filedata OLE Object (or BLOB)
contentType text
filename text
I just keep getting File does not exist.
I know the reason is because I am using mySQL syntax but my database is not mySQL.
Here is the php version I have been working on.
I truly appreciate any help.
I am completely 100% php newbie.
I have been working with asp for a while now and have been presented with the challenge of viewing a pdf with php.
I have done something similar with asp which is this:
Code:
<%
' Create ADO Connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB.1;Password=sonn1e;Persist Security Info=True;User ID=sam.okeh; " & _
"Initial Catalog=Traf;Data Source=pw2 "
Response.ContentType = "application/pdf"
' Create Recordset
Set RecSet = Server.CreateObject("ADODB.Recordset")
RecSet.Open "select fileData from TrafficCountsFiles where siteCode ='" & Request("siteCode")& "' ", Conn, 2, 3
If Not RecSet.EOF Then
' set the ContentType property
Response.Addheader "Content-Disposition", "inline; filename=file.pdf"
' send the binary data to the webbrowser
Response.BinaryWrite (RecSet("fileData"))
End If
RecSet.Close
Set RecSet = Nothing
Conn.Close
Set Conn = Nothing
Above code allows me to click on a pdf file and open on a browser to view contents.
Well, since our php guy is on a maternity leave (his wife had a baby) for 3 weeks and we needed to get this done,
I have been trying to re-write it in php.
So far, I am getting errors that I really don't know how to resolve.
I was wondering if someone could be kind enough to help me resolve this.
Here is my table structure.
Table name: Access database
ID autonumber
sitecode text
filesize number
filedata OLE Object (or BLOB)
contentType text
filename text
I just keep getting File does not exist.
I know the reason is because I am using mySQL syntax but my database is not mySQL.
Here is the php version I have been working on.
I truly appreciate any help.
Code:
<?php
// DB connection here.
$conn=odbc_connect('counts','','');
$sql = "SELECT FileData FROM trafficCountsFiles,fctrafic where fctrafic.site_code = trafficcountsFiles.sitecode and siteCode = '".$_GET["siteCode"]."'"; $rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
if (($rs) == 1)
{
$fileType = mysql_result($result, 0, "contentType");
$fileContent = mysql_result($result, 0, "filedata");
header("Content-Type: $fileType");
header("Content-Length: " . strlen($filedata));
header("Content-Disposition: inline; filename=file.pdf;");
echo $fileContent;
}
else
{
echo "Record doesn't exist.";
}
?>
[code]