473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How verify MIME type of file??

HI,
How verify MIME type of file??

Which components should I use?

Still now I couldn't find anything!

OBS.: I don´t to check file extensions!

Thanks,
--

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC

Jul 19 '05 #1
2 2759
Compile (and modify) this VB6 component. If you don't have VB6 I can compile
this for you . Of course, that DLL is given to you 'AS IS'.
------------- start code
Option Explicit
Private Const GENERIC_READ As Long = &H80000000
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Private Const FILE_FLAG_SEQUENTIAL_SCAN As Long = &H8000000
Private Const FILE_FLAG_NO_BUFFERING = &H20000000
Private Const OPEN_EXISTING As Long = 3
Private Const INVALID_HANDLE_VALUE As Long = -1
Private Const vbComError As Long = &H80070000
Private Declare Function getArrayPtr Lib "MSVBVM60.DLL" Alias "VarPtr"
(btBytes() As Byte) As Long
Private m_oResp As IResponse
Private hFile As Long
Public Sub DowloadFile(ByVal strBasePath As String, ByVal strFile As String)

Dim lSize As Long, lBlocks As Long

Const CHUNK As Long = 2048 'might be more optimal to get the NTFS cluster
size
Dim btChunk() As Byte
ReDim btChunk(2047)

Dim er As Long
Dim vChunk As Variant
Dim bytesread As Long
Dim blnOresp As Boolean
Dim sContentType As String
Dim sExt As String
Dim sTemp As String
Dim lPoint As Long
Dim hKey As Long
Dim lBufLen As Long
Dim lPtr As Long
Dim lLen As Long
lPoint = InStrRev(strFile, ".", , vbBinaryCompare)
'On Local Error GoTo errlabel
If lPoint Then
sExt = Mid$(strFile, lPoint)
hKey = RegOpenKeyEx(KEY_CLASSES_ROOT, sExt, 0, KEY_QUERY_VALUE)
lBufLen = 128
sContentType = SysAllocStringLen(ByVal 0, lBufLen)

er = RegQueryValueExStr(hKey, "Content Type", ByVal 0, REG_SZ,
sContentType, lBufLen)
RegCloseKey hKey
If er = 0 Then
SysReAllocStringLen sContentType, sContentType, lBufLen \ 2 - 1
Else
er = GetLastError
raiseeror er, "Error opening key: HKEY_CLASSES_ROOT\" + sExt
End If
End If

lLen = SysStringLen(strBasePath)
If Right$(strBasePath, 1) <> "\" Then
strBasePath = VarBstrCat(strBasePath, "\")
End If
'm_oResp.Write VarBstrCat(strBasePath, strFile)
'App.LogEvent VarBstrCat(strBasePath, strFile),
vbLogEventTypeInformation
sTemp = VarBstrCat(strBasePath, strFile)
hFile = CreateFileW(sTemp, GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, 0) 'FILE_FLAG_NO_BUFFERING
If hFile = INVALID_HANDLE_VALUE Then
er = GetLastError
raiseeror er, "Error opening file: " + strFile
End If

lSize = GetFileSize(hFile, 0)
If m_oResp Is Nothing Then
blnOresp = False
Else
blnOresp = True
m_oResp.Buffer = False
'Set the content type to the specific type that you are sending.
m_oResp.ContentType = sContentType
m_oResp.AddHeader "Content-Length", CStr(lSize)
'Content-disposition: attachment; filename=fname.ext
'm_oResp.AddHeader "Content-Description", "a complete map of the
human genome"
m_oResp.AddHeader "Content-Disposition", "attachment; filename=" +
strFile
End If

'the variant stealth method. VB does not know that vChunk and btChunk
are referring to
' the *same* memory location
' this way we avoid pumping around bytes in RAM just because of
*casting* from byte arrat to variant

lPtr = VarPtr(vChunk) + 8
kernel.MoveMemory ByVal lPtr, ByVal getArrayPtr(btChunk()), 4
kernel.MoveMemory vChunk, CInt(vbArray Or vbByte), 2

lBlocks = 1
For lBlocks = lBlocks To lSize \ CHUNK + 1

If ReadFile(hFile, btChunk(0), CHUNK, bytesread, ByVal 0&) = 0 Then
er = GetLastError
End If
If bytesread = 0 Then Exit For
If bytesread < CHUNK Then
ReDim Preserve btChunk(bytesread - 1)
kernel.MoveMemory ByVal lPtr, ByVal getArrayPtr(btChunk()), 4
End If

If blnOresp Then
If m_oResp.IsClientConnected = False Then Exit For

'BinaryWrite uses as much as CPU as a CGI application
' the only alternative seems to be ISAPI!
m_oResp.BinaryWrite vChunk
End If
Next
'lSize = lSize Mod CHUNK
'clear the variant again so that VB won't clean the same byte array
twice
kernel.MoveMemory vChunk, vbEmpty, 2

If hFile > 0 Then
CloseHandle hFile
hFile = -1
End If

Set m_oResp = Nothing
Exit Sub
ErrLabel:
raiseeror Err.Number
End Sub

Private Function GetLastError() As Long
GetLastError = Err.LastDllError
End Function
Private Sub raiseeror(ByVal er As Long, Optional ByRef sDescr As String =
vbNullString)
Dim oErr As ErrObject
Set oErr = Information.Err
If SysStringLen(sDescr) = 0 Then sDescr = oErr.Description
App.LogEvent sDescr, vbLogEventTypeError
If er Then oErr.Raise vbComError Or er, "clsDL", sDescr
End Sub
Public Sub OnStartPage(ctx As ScriptingContext)
Set m_oResp = ctx.Response
End Sub
Public Sub OnEndPage()

End Sub

Private Sub Class_Terminate()
If hFile > 0 Then CloseHandle hFile
End Sub
------------ end code

--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm

"Vilmar Brazão de Oliveira" <te***@teste.teste.teste> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
HI,
How verify MIME type of file??
Which components should I use?
Still now I couldn't find anything!
OBS.: I don´t to check file extensions!
Thanks,
--
««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC

Jul 19 '05 #2
hi,
could you compile for me?
I am without vb6 in my job, I have only in my house.
thanks
"Egbert Nierop (MVP for IIS)" <eg***********@nospam.com> escreveu na
mensagem news:uu*************@tk2msftngp13.phx.gbl...
Compile (and modify) this VB6 component. If you don't have VB6 I can compile this for you . Of course, that DLL is given to you 'AS IS'.
------------- start code
Option Explicit
Private Const GENERIC_READ As Long = &H80000000
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Private Const FILE_FLAG_SEQUENTIAL_SCAN As Long = &H8000000
Private Const FILE_FLAG_NO_BUFFERING = &H20000000
Private Const OPEN_EXISTING As Long = 3
Private Const INVALID_HANDLE_VALUE As Long = -1
Private Const vbComError As Long = &H80070000
Private Declare Function getArrayPtr Lib "MSVBVM60.DLL" Alias "VarPtr"
(btBytes() As Byte) As Long
Private m_oResp As IResponse
Private hFile As Long
Public Sub DowloadFile(ByVal strBasePath As String, ByVal strFile As String)
Dim lSize As Long, lBlocks As Long

Const CHUNK As Long = 2048 'might be more optimal to get the NTFS cluster
size
Dim btChunk() As Byte
ReDim btChunk(2047)

Dim er As Long
Dim vChunk As Variant
Dim bytesread As Long
Dim blnOresp As Boolean
Dim sContentType As String
Dim sExt As String
Dim sTemp As String
Dim lPoint As Long
Dim hKey As Long
Dim lBufLen As Long
Dim lPtr As Long
Dim lLen As Long
lPoint = InStrRev(strFile, ".", , vbBinaryCompare)
'On Local Error GoTo errlabel
If lPoint Then
sExt = Mid$(strFile, lPoint)
hKey = RegOpenKeyEx(KEY_CLASSES_ROOT, sExt, 0, KEY_QUERY_VALUE)
lBufLen = 128
sContentType = SysAllocStringLen(ByVal 0, lBufLen)

er = RegQueryValueExStr(hKey, "Content Type", ByVal 0, REG_SZ,
sContentType, lBufLen)
RegCloseKey hKey
If er = 0 Then
SysReAllocStringLen sContentType, sContentType, lBufLen \ 2 - 1 Else
er = GetLastError
raiseeror er, "Error opening key: HKEY_CLASSES_ROOT\" + sExt
End If
End If

lLen = SysStringLen(strBasePath)
If Right$(strBasePath, 1) <> "\" Then
strBasePath = VarBstrCat(strBasePath, "\")
End If
'm_oResp.Write VarBstrCat(strBasePath, strFile)
'App.LogEvent VarBstrCat(strBasePath, strFile),
vbLogEventTypeInformation
sTemp = VarBstrCat(strBasePath, strFile)
hFile = CreateFileW(sTemp, GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, 0) 'FILE_FLAG_NO_BUFFERING
If hFile = INVALID_HANDLE_VALUE Then
er = GetLastError
raiseeror er, "Error opening file: " + strFile
End If

lSize = GetFileSize(hFile, 0)
If m_oResp Is Nothing Then
blnOresp = False
Else
blnOresp = True
m_oResp.Buffer = False
'Set the content type to the specific type that you are sending.
m_oResp.ContentType = sContentType
m_oResp.AddHeader "Content-Length", CStr(lSize)
'Content-disposition: attachment; filename=fname.ext
'm_oResp.AddHeader "Content-Description", "a complete map of the
human genome"
m_oResp.AddHeader "Content-Disposition", "attachment; filename=" +
strFile
End If

'the variant stealth method. VB does not know that vChunk and btChunk
are referring to
' the *same* memory location
' this way we avoid pumping around bytes in RAM just because of
*casting* from byte arrat to variant

lPtr = VarPtr(vChunk) + 8
kernel.MoveMemory ByVal lPtr, ByVal getArrayPtr(btChunk()), 4
kernel.MoveMemory vChunk, CInt(vbArray Or vbByte), 2

lBlocks = 1
For lBlocks = lBlocks To lSize \ CHUNK + 1

If ReadFile(hFile, btChunk(0), CHUNK, bytesread, ByVal 0&) = 0 Then er = GetLastError
End If
If bytesread = 0 Then Exit For
If bytesread < CHUNK Then
ReDim Preserve btChunk(bytesread - 1)
kernel.MoveMemory ByVal lPtr, ByVal getArrayPtr(btChunk()), 4
End If

If blnOresp Then
If m_oResp.IsClientConnected = False Then Exit For

'BinaryWrite uses as much as CPU as a CGI application
' the only alternative seems to be ISAPI!
m_oResp.BinaryWrite vChunk
End If
Next
'lSize = lSize Mod CHUNK
'clear the variant again so that VB won't clean the same byte array
twice
kernel.MoveMemory vChunk, vbEmpty, 2

If hFile > 0 Then
CloseHandle hFile
hFile = -1
End If

Set m_oResp = Nothing
Exit Sub
ErrLabel:
raiseeror Err.Number
End Sub

Private Function GetLastError() As Long
GetLastError = Err.LastDllError
End Function
Private Sub raiseeror(ByVal er As Long, Optional ByRef sDescr As String =
vbNullString)
Dim oErr As ErrObject
Set oErr = Information.Err
If SysStringLen(sDescr) = 0 Then sDescr = oErr.Description
App.LogEvent sDescr, vbLogEventTypeError
If er Then oErr.Raise vbComError Or er, "clsDL", sDescr
End Sub
Public Sub OnStartPage(ctx As ScriptingContext)
Set m_oResp = ctx.Response
End Sub
Public Sub OnEndPage()

End Sub

Private Sub Class_Terminate()
If hFile > 0 Then CloseHandle hFile
End Sub
------------ end code

--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm

"Vilmar Brazão de Oliveira" <te***@teste.teste.teste> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
HI,
How verify MIME type of file??
Which components should I use?
Still now I couldn't find anything!
OBS.: I don´t to check file extensions!
Thanks,
--
««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vilmar Brazão de Oliveira | last post by:
Hi, How verify type or extension of file using ASPUPLOAD? I check documentation, but I didn't find anything else yet. thanks, -- ««««««««»»»»»»»»»»»»»» Vlmar Brazão de Oliveira...
0
by: clevariant | last post by:
Hello, I'm tasked with creating a WSDL file that is compatible with .NET's code gen' tool, wsdl.exe. I'm getting an error in the code output saying "Missing soap:body input binding", which...
1
by: Michael Loughry | last post by:
I'm writing a web application that fetches documents from the server and sends them to the client. I do this using the Response.BinaryWrite method. However, is there any way to detect the MIME...
5
by: splodge | last post by:
This may seem like a stupid question but I want to check before I go ahead and build this... I am working on a portal, part of which allows users to upload files. Part of the array within...
0
by: service | last post by:
This is a multi-part message in MIME format --siNt1NhCoyB3mEPydjXJyOTcg=_X6kQe0H0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable - This mail is a HTML mail. Not all...
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
0
by: comp.lang.php | last post by:
if (!function_exists('mime_content_type_fileinfo')) { /** * Will use {@link http://us2.php.net/fileinfo FileInfo} functions provided within {@link http://pecl.php.net PECL} bundle to return mime...
1
by: comp.lang.php | last post by:
<pre> if (!function_exists('mime_content_type_fileinfo')) { /** * Will use {@link http://us2.php.net/fileinfo FileInfo} functions provided within {@link http://pecl.php.net PECL} bundle to return...
6
by: Mad Hatter | last post by:
Hi folks I'm a bit confused with an upload script that I've written. I want to be able to check the file type of an upload by checking the mime type but I'm not getting the results that I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.