MarioM1977
Posts: 23
|
Posted: 07/11/2011, 4:53 AM |
|
Dear Colleagues,
I'm really new in PHP but trying to learn a lot. Now I need to create a simple page to upload PDF file to MS SQL table. What I have now?
MS SQL table Archive with fields:
DocID (int, autoincremental) - record ID
DocNumber (varchar) - some text field for manual text input
DocDate (datetime) - manual date input
DocFile - (image) - blob field for PDF file
DocFileName (varchar) - field for file name
I already created a simple page with two grids:
- grid name Archive shows all records
- record grid name Archive1 allows to add/edit/delete records
Uploading file component FileUpload1 already added and working well if I store a PDF files on server disk as a normal file.
Here is my zipped CCS 4.3 project: http://tetrapak.home.pl/pub/ISPArchive.zip
I have a similar working project (blob saving) created in CCS2 (ASP) long time ago by someone. I have here 3 custom events added for record grid:
After Insert
Dim Inserted, SQL, RS
SQL = "SET NOCOUNT ON SELECT SCOPE_IDENTITY()"
RS = DBIntranet.Execute(SQL)
Inserted = CLng(CCGetValue(RS,0))
SQL = "INSERT INTO ContractsData([FileID]) VALUES(" & Inserted & ")"
RS = DBIntranet.Execute(SQL)
Redirect = FileName & "?s_FileID=" & Inserted
Before Update
' -------------------------
Dim Recordset, ContentType
Set Recordset = Server.CreateObject("ADODB.Recordset")
Recordset.Open "SELECT * FROM ContractsData WHERE [FileID]=" & CCGetParam("s_FileID",0), ContractsDetails.DataSource.Connection.Connection, 2, 2
If Not Recordset.EOF And objUpload.Files("FileUpload1_File").FileName<>"" Then
objUpload.Files("FileUpload1_File").FileObject.SaveToDatabase Recordset.Fields("FileBinary")
Recordset.Fields("FileName") = objUpload.Files("FileUpload1_File").FileObject.FileName
Recordset.Fields("FileSize") = objUpload.Files("FileUpload1_File").FileObject.Size
Recordset.Fields("FileContentType") = objUpload.Files("FileUpload1_File").FileObject.ContentType
Recordset.Update
End If
Recordset.Close
Set Recordset = Nothing
Before Exectute Update: ContractsDetails.FileUpload1.DeleteFile
I could try to some ASP to PHP converter to migrate this code to PHP but is that way ok?
I will be really greatful to anybody for any help.
Brgds
Mariusz
|