=================== fup.html ================ <HTML><BODY> <FORM ACTION="fup.asp" ENCTYPE="multipart/form-data" METHOD=POST> ¼: <INPUT TYPE=TEXT NAME="yourname"><BR> t@CP: <INPUT TYPE=file NAME="file1"><BR> t@CQ: <INPUT TYPE=file NAME="file2"><BR> <INPUT TYPE=SUBMIT NAME=UPLOAD> </FORM></BODY></HTML> =================== fup.html end ============ =================== fup.asp ================= <% set obj=server.createobject("fileup") name=obj.FormData("yourname") f1=obj.FileName("file1") newf1="d:\temp\fup" & Mid(f1,InstrRev(f1,"\")) fsize1=obj.SaveAs("file1",newf1) %> <HTML><HEAD><TITLE>File Upload Test</TITLE> <BODY> <H1>Testing</H1> <BR> <%= name %>³ñA<%= newf1 %>ÉAbv[h³êܵ½<BR> t@CTCY= <%= fsize1 %><BR> =================== fup.asp end =============±±ÅÍ̱ƪwKÅ«Ü·B
NCAg©çf[^ðóæéÌÉIRequestC^tF[Xðg¤ÌÅA
[ActiveXT[oR|[lg]ðNbNµÄIðµÄA[Ö]ðµÜ·B
[ATL Object WizardÌvpeB]_CAOªJ«Ü·B
[¼O]y[WÌ[C++ V[g]ɼOðüêéÆ©®IÉ
·×ÄÌeLXg{bNXÉftHg̼OªüèÜ·B
.H t@CÆ.CPPt@C̼OÆProg ID̼OðÏXµÜ·B
[Prog ID]ªO©ç±ÌR|[lgðANZX·éÆ«Éwè·é¼OÆÈèÜ·B
ASPÌVBScriptÌServer.CreateObject\bhÅIuWFNgð쬷éÆ«Ég¢Ü·B
±ÌáÅÍASet obj = Server.CreateObject("FileUp")ÉÈèÜ·B
[®«]y[WÅÍð`FbNµÜ·B
[ASP]y[WÅÍð`FbNµÜ·BvÆÍASPÌIRequestIuWFNg̱ÆÅ·B
SaveAs\bhðÌæ¤ÉwèµÜ·B [in] BSTR name,[in] BSTR fpath,[out,retval] long *pVal
¯¶æ¤ÉÌ\bhàÇÁµÜ·B
FormData [in] BSTR name,[out,retval] BSTR *pVal
FileName [in] BSTR fname,[out,retval] BSTR *pVal
fileupx.cpp (u·µÜ·) fileupx.h (u·µÜ·) brfc1867.h brfc1867.cpp »Ì¼·×ÄÌvWFNgt@CªÜÜêÄÜ·ªRs[·éÌÍA ãÌSÂÌt@C¾¯ÉµÜ·B ========================================================================= ·®µ½¢lâèǨèâÁÄà¤Ü¢©È¢êÍA ðµ½SÄÌt@CðfileupfBNgÉRs[µÄ fileup.dswðNbN·êÎvWFNgªJ«Ü·ÌÅ·®rhÅ«Ü·B AµA±Ìfileup.dswt@CÍVisual C++ 6.0ÎÅ·B Visual C++ 5.0ÅÍrhūܹñB ========================================================================= 2. vWFNgÉt@CðÇÁ
[vWFNg]-[vWFNgÉÇÁ]-[t@C]ÅÇÁµÜ·B brfc1867.h brfc1867.cpp 3. Fileupx.cppt@C
FileUpx.cppÍAÌæ¤ÉÈèÜ·B // FileUpx.cpp : CFileUp ÌCve[V #include "stdafx.h" #include "FileUp.h" #include "FileUpx.h" ///////////////////////////////////////////////////////////////////////////// // CFileUp STDMETHODIMP CFileUp::OnStartPage (IUnknown* pUnk) { if(!pUnk) return E_POINTER; CComPtr<IScriptingContext> spContext; HRESULT hr; // IScriptingContext C^[tFCXÌæ¾ hr = pUnk->QueryInterface(IID_IScriptingContext, (void **)&spContext); if(FAILED(hr)) return hr; // Request IuWFNgÌ|C^ðæ¾ hr = spContext->get_Request(&m_piRequest); if(FAILED(hr)) { spContext.Release(); return hr; } // Abv[hf[^ðRequest.BinaryReadÅÛ¶ m_rfc1867.Open(m_piRequest); m_bOnStartPageCalled = TRUE; return S_OK; } STDMETHODIMP CFileUp::OnEndPage () { m_rfc1867.Close(); // obt@ðJú m_bOnStartPageCalled = FALSE; // ·×ÄÌC^[tFCXððúµÜ· m_piRequest.Release(); return S_OK; } STDMETHODIMP CFileUp::SaveAs(BSTR name, BSTR fpath, long *pVal) { USES_CONVERSION; LPCSTR szName = OLE2T(name); LPCSTR szFileName = OLE2T(fpath); int flen; char *tf = m_rfc1867.FileData(szName,&flen); if(tf == NULL || flen < 1) { *pVal = -2; return S_OK; } HANDLE hFile = CreateFile((const char*)szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { *pVal = -3; return S_OK; } DWORD dwAmt; if(!WriteFile(hFile, tf, flen, &dwAmt, NULL)) { CloseHandle(hFile); *pVal = -4; return S_OK; } CloseHandle(hFile); *pVal = dwAmt; return S_OK; } STDMETHODIMP CFileUp::FormData(BSTR fname, BSTR *pVal) { USES_CONVERSION; LPCSTR szName = OLE2T(fname); int dlen; char *name = m_rfc1867.FormData(szName,&dlen); if(name == NULL) { *pVal = A2BSTR(""); return S_OK; } int mlen = dlen + 4096; char *tp = new char[mlen]; if (tp == NULL) { delete [] name; return ResultFromScode(E_OUTOFMEMORY); } memcpy(tp,name,dlen); tp[dlen] = 0; int clen = dlen; delete [] name; name = m_rfc1867.FormData(szName,&dlen); while (name) { tp[clen++] = '\t'; if (mlen < (clen + dlen + 1)) { char *tp2 = new char[mlen+dlen + 4096]; if (tp2 == NULL) { delete [] tp; delete [] name; return ResultFromScode(E_OUTOFMEMORY); } memcpy(tp2,tp,clen); delete [] tp; tp = tp2; mlen += dlen + 4096; } memcpy(tp+clen,name,dlen); clen += dlen; tp[clen] = 0; delete [] name; name = m_rfc1867.FormData(szName,&dlen); } *pVal = A2BSTR(tp); delete [] tp; return S_OK; } STDMETHODIMP CFileUp::FileName(BSTR fname, BSTR *pVal) { USES_CONVERSION; LPCSTR szName = OLE2T(fname); char *name = m_rfc1867.FileName(szName); if(name == NULL) { *pVal = A2BSTR(""); return S_OK; } *pVal = A2BSTR(name); delete [] name; return S_OK; }
LIBCMT.lib(crt0.obj) : error LNK2001: O¼ÝÎÞÙ "_main" Í¢ðÅ· ReleaseMinDependency/FileUp.dll : fatal error LNK1120: OQÆ 1 ª¢ðÅ·B link.exe ÌÀs´×° FileUp.dll - ´×° 2Ax 0 ±ÌG[ÍAC^CÖªN³êĢȢƫɶµÜ·B CÌ^CÖðvWFNgàÅgÁÄ¢éƶµÜ·B ReleaserhÌftHgÅÍATL COM AppWizardÍAC^CðNµÜ¹ñB ±êÍA_ATL_MIN_CRTvvZbT¶ªwè³êÄ¢é½ßÅ·B ÎôƵÄÍF [vWFNgÌÝè] -[C/C++]-[vvZbTÌè`]Å_ATL_MIN_CRTðí ±¤·éÆCÌ^CªN³êÄG[ªÁ¦Ü·B ±ê¾¯ÅnjÅ·B à¤êÂÌû@ÍF CÌ^CÖðg¤Ìðâßé strlen ÈÇÌÖð lstrlen ÈÇÉÏXµÜ·B ¡ñÍA_ATL_MIN_CRTÍ»ÌÜÜɵÄACÌ^CÖðg¤ÌðâßÄ ±ÌâèÉεܷB brfc1867.cpp t@CÌstrnicmpÖª»ÌÆlÅ·B if (strnicmp(disp,(char*)tp+offset,dlen) != 0) break; // if (CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, // disp,dlen,(char*)tp+offset,dlen) != CSTR_EQUAL) // break; ±êðÌæ¤ÉstrnicmpÖÌãíèÉCompareStringÖð g¤æ¤ÉC³µÜ·BRgðt¯Ö¦é¾¯Å·B // if (strnicmp(disp,(char*)tp+offset,dlen) != 0) // break; if (CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, disp,dlen,(char*)tp+offset,dlen) != CSTR_EQUAL) break; rhµÄG[ªÁ¦êÎOKÅ·B
[!ProgID] = s '[!TypeName]' { CLSID = s '{[!ObjectGUID]}' [!if=(InsertableEnabled, "TRUE")] 'Insertable' [!endif] } [!VersionIndependentProgID] = s '[!TypeName]' { CLSID = s '{[!ObjectGUID]}' <=== ±ÌsðÇÁ CurVer = s '[!ProgID]' } ±êÅñ©çrh·éƫɳµo^³êéæ¤ÉÈèÜ·B vWFNgÌFileUp.rgst@CðèÅÒWµÄà©Ü¢Ü¹ñB CurVerÌsÌOÉCLSIDÌsðÌæ¤ÉRs[µÄ¾³¢B FileUp.1 = s 'FileUp Class' { CLSID = s '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' } FileUp = s 'FileUp Class' { CLSID = s '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' CurVer = s 'FileUp.1' }