PHP Click button Automatic Download, IE has a problem, ask for answers!

Source: Internet
Author: User
Tags urlencode

Look directly at the code!

test.php

<?PHPinclude_once(' index.php ');? ><! DOCTYPE html>var str = "data:image/png;base64,ivborw0kggoaaaansuheugaaagqaaabkcayaaabw4pvuaaagtuleqvr4xu2d4vljmaye6fs/ nnd0chfyur9dxyecuhl+3mr2hk12txjaul29vb3ff07/e3/flrndbvj647x1ujy/gjveio4b7dhzd3z/uq8cjpvajxinyefeklbfcghlx4by+ hbzpleg0vxovsoceh7an2u1sy3mz8z+zag9qaoyj0admstjzzhe0dki+ Hkd10co6xmzo7hofifzzbcohiijst4jgxtkvgnydzubu2xafhs4bkbcsgziesqlmi68rdsoguv0ldozh8nby0pwpvenyabjl9yqkrpnr1c9pllvytb437nrns dlkurwvopitanyckldjhwsi58vyxdnwz0jckfnelyhsp/z3fn3x9yntlvi+da+y9rhg1qwu6g/kyanyboemifs5ynbr6m8/pidqo00fgt+d9+ laq9cb0cck4csiswdoascxtzuwtxlbvv2izotqjcehmqsidweh5pyzq+vmq2iwzbkgn05dchpa4soq16nlnemzgq2nhq/ sl2vprw8mggzogbc6q2ynku9xlekqxpcnsjohgdsth4gdamypkgtzgfsjybkkknfi2qimu+w7ey+ zt7lcxspkyxbs7a1adki0iacssfpqdtamcucsrzdtxlyvyadliqflnjiynm61pg8cick+ 3tw9jdr6pgoekp5tfdzragjp99m7nf3uljwecfglikztprqnqnohyz6ue/qwzqyf9peztbrn5kzqpy2ihce4njlzsg+ nszjwot6rf8db6kstwxckupic6uqkwfw9pdj4bt3iq6dusshx/ rxhrgbgajmgwta4g9jpcx01ic4ncdrr3i2vsdvniwtcwitys2dzpa87pxaa7kfo5oquwfrz7loei6yb3nsie1uexy2olazgkisupqpi/ Ou1uks43enqwpa9l+5aec+0ixmyuhumelrswyclxvjicnnki+otdisr5jgmujborrsgnq+jdwalb4+ of5rbfflmgs1vrkfhxkigtna0fwoybr4rxljvmxyi46ewj6kadl3z5rcfgsldqgtkn6hen2pu3ekqsogckaw9vvmuqyo/ cbyf4fz1gsq2kwdssfpl7ms20vz4zr7ii09u0b/nuooqfpgkdgkq5x5ncfrqyl5pp0pkqu+fvxqsul9iljwpkvkogh8kk/ hmuunsnvc3oaiv7gomv/haklou1gvuo2zbcexpllzyrcpsfpnqyy0iatddl1xuqq+1pag5jsaiq+dbauixwfxusplkevq8mt9crmt0jv1s/ axayl/qdqjw19rcdvzdoocjpped5w1bc6+neyp2kq6u+n9dntsqbwy4gjohzpkqgfzsvdk1/ mvywid9llrjq5tcxsc4tw4swwnc89zsvynerhxxk6vjn/ 6vvpj1aapcn30gmc5dcjicj6omagzvqiagflngbivdcfzkaw48kvjqxjsfeqaiun7wfvisrw5tm1va+ ifesoga1gvajgvfwiqyrrlbwx9cq7vhev8ymeawwd5k4tzdwhaygvtal1lkgbi9teanex3ak7rhobkbze8derbssizzkj9ce1vkthvana4pq8h6z /ei+xdnkamaehgsaerkekzt903js1tibpgp097cx3agglxxyupmqjksei+ nror9vi7yyoaw8gwulovubagji5aypczh4tuq1rpwnaz2wcpzkl9kd2vxk+z14du/ ggmnbhr9qzkykbsy6g2usdpegriwkoyaarbchqptd8rfyg6z5reelalkfntrad62gmdsowowhxqtqmipcwf9cuaobms4tn/g+i8ogltda1kb+ A8qwoemxzpe51nrha4qt1qz0nnjohrpkstzgdsa+kgmix1guymxaku7ldxwaqmkaurnvy6dcj3ge2xuu8xxg3iea16du1d+vraifbkzz35luzdzrh8gocs56csjjwgfdmelrqgp73qjhuqfaqctows5qq0ygrnpmxa2eu/jifelyf6tqzehds5fywka/ s6lmpbsu2upmxvh6h9hooyycvlgyuo553a1odco9um0c/khlj7//nvryoclsxiwnmspv2rpc2uk+tqc1wvy1gnbyzdp401idn0lzak8+ nqpxiynlkamrvq70afmqq621cdmibcqxskjtzqqbkd8smyqjjafp8ekitnkyoqvkkhnuosal/kguuyy49oznr/6geu0+ayk89gcl/uhuqge/ zw2slb6yxkzvod4krt+jcdupxc2wi8kjnprzkmudakgots0zhhy9+hul1pqpyp34akdyoy+iqg/aojmz5hjva3fgaaaabjru5erkjggg== "; function $urlEncode(str) {//Direct post, the browser will turn the + number, there is a pit            if(str && str.length) {                returnEscape (str). replace (/\+/g, '%2b '). Replace (/\ "/g, '%22 '). Replace (/\ '/g, '%27 '). Replace (/\//g, '%2f '); } return""; } document.getElementById (' btn '). onclick = function () {document.getElementById (' btn '). SetAttribute (' href ', ' test.php?file= ' +$urlEncode(str)); } </script></body>

index.php

<?PHP$base 64_url=UrlDecode($_get[' file ']);//Decode Firstif($base 64_url){    Define(' WWWROOT ',dirname(__file__).‘ \\‘); $base 64_url=Preg_replace('/\s/', ' + ',$base 64_url);//space Change + sign    $base 64_body=substr(strstr($base 64_url, ', '), 1); $rand=Rand(100, 999); $pics=Date("Ymdhis").$rand.$type;//named picture name    $filename= './'.$pics.‘. jpg; $name=$pics.‘. jpg; $img=Base64_decode($base 64_body);//decoding    $a=file_put_contents($filename,$img);//Picture bytes    $path= WWWROOT.$name;//full File Save path    $src= ' http://127.0.0.1/download/'.$name;//full picture URL path    Header("Cache-control:no-cache"); Header("Pragma:no-cache"); Header("expires:0"); Header(' Cache-control:public, must-revalidate, Max-age=0 '); Header(' Accept-ranges:bytes '); Header("Content-type:application/force-download"); Header("Content-type:application/download"); Header("Content-transfer-encoding:binary"); Header("Content-type:application/octet-stream"); Header(' Cache-control:must-revalidate, post-check=0, pre-check=0 ');//if not added, IE will prompt the target host cannot access    Header(' Pragma:public ');//if not added, IE will prompt the target host cannot access    Header("Content-length:".)filesize($path)); Header("Content-disposition:attachment; Filename=$name"); $fp=fopen($src, ' RB '); Fpassthru($fp); fclose($fp); if(file_exists($path)){//and delete the picture .        unlink($path); Exit; }}    ?>

Pro-Test, Chrome and Firefox are fine. But there is a bug under IE, ask Daniel pointing!

PHP Click button Automatic Download, IE has a problem, ask for answers!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.