CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How to store a PDF file as a BLOB in MS SQL table

Print topic Send  topic

Author Message
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
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 07/11/2011, 8:22 PM

MarioM1977,

Any reason why you want to store the PDF in the database? Just wondering...
View profile  Send private message
MarioM1977

Posts: 23
Posted: 07/11/2011, 11:11 PM

Quote mamboBROWN:
Any reason why you want to store the PDF in the database? Just wondering...

Due to some other reason, I need to migrate current working sulution (ASP) to PHP. The current solution is based on SQL DB and blobs. It's working really fine. So, why do not have the same in PHP?
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 07/13/2011, 9:26 PM

MarioM1977,

I personally have never done this before but I did do a little research on the web to see what I could come up with. Here is a link to get you started:

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials...l-database.aspx

Hopefully this helps...
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.