J
J
Johnick2019-04-11 11:16:49
PHP
Johnick, 2019-04-11 11:16:49

How to get attachments from MS SQL database?

Greetings.
There is a MS SQL DB in which attachments are stored in one of the tables (the format of attachments can be any) in the VARBINARY (MAX) field.
As usual, there is no access to the script sources that added files to the database.
How to properly get these attachments using PHP and give them to the user for downloading, or save them to a file?
At the moment, with a simple select (without any transformations), it turns out to get PDF files of small size ~ up to 60 Kb. If the size is larger, or files of a different format, then the file is broken.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-04-11
@Johnick

Extracting binary data .
There is something in front of the picture.
Is the data in the database correct? For JPG should beSELECT CONVERT(varchar(10), Photo, 2) FROM PhotoFFD8FFE000
First 10 characters : ACED000575 if you don’t know what the system mixes in there, you won’t be able to get the data normally?
Yes. This is no longer MS SQL, this is a converted file.
But one can try, for example, can a valid PDF be "Java data ser... . That is, your PDF reader discards the data before the signature. For other files, try discarding the first 27 bytes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question