{"id":782,"date":"2011-11-18T00:22:17","date_gmt":"2011-11-17T16:22:17","guid":{"rendered":""},"modified":"2014-03-11T22:40:44","modified_gmt":"2014-03-11T14:40:44","slug":"asp%e5%ae%9e%e4%be%8b%ef%bc%9a%e8%a7%a3%e5%86%b3asp%e5%9b%be%e5%83%8f%e4%b8%8a%e4%bc%a0%e6%bc%8f%e6%b4%9e","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2011\/11\/18\/782.htm","title":{"rendered":"ASP\u5b9e\u4f8b\uff1a\u89e3\u51b3ASP\u56fe\u50cf\u4e0a\u4f20\u6f0f\u6d1e"},"content":{"rendered":"<p>\u5e38\u542c\u8bf4\u7684ASP\u4e0a\u4f20\u6f0f\u6d1e\uff0c\u5373\u662f\u5c06\u4e00\u4e9b\u6728\u9a6c\u6587\u4ef6\u4fee\u6539\u540e\u7f00\u540d\uff08\u4fee\u6539\u4e3a\u56fe\u50cf\u6587\u4ef6\u540e\u7f00\uff09\uff0c\u8fdb\u884c\u4e0a\u4f20\u3002<\/p>\n<p>\u9488\u5bf9\u6b64\u60c5\u51b5\u4f7f\u7528\u4e0b\u5217\u51fd\u6570\u8fdb\u884c\u8fa8\u522b\uff1a<br \/>\n&lt;%<br \/>\n&#8216;******************************************************************<br \/>\n&#8216;CheckFileType \u51fd\u6570\u7528\u6765\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u4e3a\u56fe\u7247\u6587\u4ef6<br \/>\n&#8216;\u53c2\u6570filename\u662f\u672c\u5730\u6587\u4ef6\u7684\u8def\u5f84<br \/>\n&#8216;\u5982\u679c\u662f\u6587\u4ef6jpeg,gif,bmp,png\u56fe\u7247\u4e2d\u7684\u4e00\u79cd\uff0c\u51fd\u6570\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse<br \/>\n&#8216;******************************************************************<\/p>\n<p>const adTypeBinary=1<\/p>\n<p>dim jpg(1):jpg(0)=CByte(&amp;HFF):jpg(1)=CByte(&amp;HD8)<br \/>\ndim bmp(1):bmp(0)=CByte(&amp;H42):bmp(1)=CByte(&amp;H4D)<br \/>\ndim png(3):png(0)=CByte(&amp;H89):png(1)=CByte(&amp;H50):png(2)=CByte(&amp;H4E):png(3)=CByte(&amp;H47)<br \/>\ndim gif(5):gif(0)=CByte(&amp;H47):gif(1)=CByte(&amp;H49):gif(2)=CByte(&amp;H46):gif(3)=CByte(&amp;H39):gif(4)=CByte(&amp;H38):gif(5)=CByte(&amp;H61)<\/p>\n<p>function CheckFileType(filename)<br \/>\non error resume next<br \/>\nCheckFileType=false<br \/>\ndim fstream,fileExt,stamp,i<br \/>\nfileExt=mid(filename,InStrRev(filename,&quot;.&quot;)+1)<br \/>\nset fstream=Server.createobject(&quot;ADODB.Stream&quot;)<br \/>\nfstream.Open<br \/>\nfstream.Type=adTypeBinary<br \/>\nfstream.LoadFromFile filename<br \/>\nfstream.position=0<br \/>\nselect case fileExt<br \/>\ncase &quot;jpg&quot;,&quot;jpeg&quot;<br \/>\nstamp=fstream.read(2)<br \/>\nfor i=0 to 1<br \/>\nif ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false<br \/>\nnext<br \/>\ncase &quot;gif&quot;<br \/>\nstamp=fstream.read(6)<br \/>\nfor i=0 to 5<br \/>\nif ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false<br \/>\nnext<br \/>\ncase &quot;png&quot;<br \/>\nstamp=fstream.read(4)<br \/>\nfor i=0 to 3<br \/>\nif ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false<br \/>\nnext<br \/>\ncase &quot;bmp&quot;<br \/>\nstamp=fstream.read(2)<br \/>\nfor i=0 to 1<br \/>\nif ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false<br \/>\nnext<br \/>\nend select<br \/>\nfstream.Close<br \/>\nset fseteam=nothing<br \/>\nif err.number&lt;&gt;0 then CheckFileType=false<br \/>\nend function<br \/>\n%&gt;<\/p>\n<p>\u90a3\u4e48\u5728\u5e94\u7528\u7684\u65f6\u5019<br \/>\nCheckFileType(server.mappath(&quot;cnbruce.jpg&quot;))<br \/>\n\u6216\u8005<br \/>\nCheckFileType(&quot;F:\/web\/164\/images\/cnbruce.jpg&quot;))<\/p>\n<p>\u53cd\u6b63\u5373\u662f\u68c0\u6d4b\u9a8c\u8bc1\u672c\u5730\u7269\u7406\u5730\u5740\u7684\u56fe\u50cf\u6587\u4ef6\u7c7b\u578b\uff0c\u8fd4\u56de true \u6216 false\u503c<\/p>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u60c5\u51b5\u5e94\u7528\u5728\u56fe\u50cf\u4e0a\u4f20\u4e2d\uff0c\u76ee\u524d\u7684\u529e\u6cd5\u662f\u5148\u5141\u8bb8\u8be5&ldquo;\u4f2a\u56fe\u50cf&rdquo;\u6587\u4ef6\u7684\u4e0a\u4f20\uff0c\u63a5\u7740\u4f7f\u7528\u4ee5\u4e0a\u7684\u81ea\u5b9a\u4e49\u51fd\u6570\u5224\u65ad\u8be5\u6587\u4ef6\u662f\u5426\u7b26\u5408\u56fe\u50cf\u7684\u89c4\u8303\uff0c\u82e5\u662f\u6728\u9a6c\u4f2a\u88c5\u7684\u56fe\u50cf\u6587\u4ef6\u5219FSO\u5220\u9664\u4e4b\uff0c\u6bd4\u5982\uff1a<br \/>\nfile.SaveAs Server.mappath(filename) &#8216;\u4fdd\u5b58\u6587\u4ef6<br \/>\nIf not CheckFileType(Server.mappath(filename)) then<br \/>\nresponse.write &quot;\u9519\u8bef\u7684\u56fe\u50cf\u683c\u5f0f&quot;<br \/>\nSet fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br \/>\nSet ficn = fso.GetFile(Server.mappath(filename))<br \/>\nficn.delete<br \/>\nset ficn=nothing<br \/>\nset fso=nothing<br \/>\nresponse.end<br \/>\nend if<\/p>\n<p>\u5219\u662f\u5148\u5c06\u6587\u4ef6\u4e0a\u4f20\uff0c\u63a5\u7740\u7acb\u9a6c\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u5224\u65ad\u6587\u4ef6\u56fe\u50cf\u7c7b\u578b\u7684\u543b\u5408\u6027\uff0cFSO\u505a\u51fa\u5220\u9664\u8be5\u6587\u4ef6\u7684\u64cd\u4f5c\u3002<\/p>\n<p>ASP\u4e0a\u4f20\u6f0f\u6d1e\u8fd8\u5229\u7528&quot;\\0&quot;\u5bf9filepath\u8fdb\u884c\u624b\u811a\u64cd\u4f5c<br \/>\n\u9488\u5bf9\u8fd9\u6837\u7684\u60c5\u51b5\u53ef\u4f7f\u7528\u5982\u4e0b\u51fd\u6570:<br \/>\nfunction TrueStr(fileTrue)<br \/>\nstr_len=len(fileTrue)<br \/>\npos=Instr(fileTrue,chr(0))<br \/>\nif pos=0 or pos=str_len then<br \/>\nTrueStr=true<br \/>\nelse<br \/>\nTrueStr=false<br \/>\nend if<br \/>\nend function<\/p>\n<p>\u63a5\u7740\u5c31\u53ef\u5224\u65ad\u540e\u518d\u505a\u6587\u4ef6\u7684\u4e0a\u4f20<\/p>\n<p>if TrueStr(filename)=false then<br \/>\nresponse.write &quot;\u975e\u6cd5\u6587\u4ef6&quot;<br \/>\nresponse.end<br \/>\nend if<\/p>\n<p>file.SaveAs Server.mappath(filename)<br \/>\n%&gt;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u542c\u8bf4\u7684ASP\u4e0a\u4f20\u6f0f\u6d1e\uff0c\u5373\u662f\u5c06\u4e00\u4e9b\u6728\u9a6c\u6587\u4ef6\u4fee\u6539\u540e\u7f00\u540d\uff08\u4fee\u6539\u4e3a\u56fe\u50cf\u6587\u4ef6\u540e\u7f00\uff09\uff0c\u8fdb\u884c\u4e0a\u4f20\u3002 \u9488\u5bf9\u6b64\u60c5\u51b5\u4f7f\u7528\u4e0b\u5217\u51fd\u6570\u8fdb\u884c\u8fa8\u522b\uff1a &lt;% &#8216;**********************************************&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-782","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=782"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/782\/revisions"}],"predecessor-version":[{"id":66619,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/782\/revisions\/66619"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=782"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=782"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}