javascript - Canvas images sent with data URI in request are corrupted after saving -
here javascript code:
function common_save_project() { var image = common_screenshot(); $.ajax ( { type: "post", processdata: false, url: site_url + "/system/xml/import/" + app_type + "/" + session_id + "/?prjid=" + project_id, data: "xml=" + common_order_xml + "&prodid=" + product_id + "&file=" + image.src } ).done(function( msg ) { alert("project saved. " + msg); }); } function common_screenshot() { var canvas = document.getelementbyid("save_image_canvas"); rasterizehtml.drawhtml(document.getelementbyid("mattes").innerhtml, canvas); var ctx = canvas.getcontext('2d'); ctx.drawimage(matte_canvas, 0, 0); var image = new image(); image.src = canvas.todataurl("image/jpeg"); return image; }
here php code:
function xmlp_import_project ( $type, $sessid ) { // save jpg thumbnail file $jpg = xmlp_f_save_jpg( $_post['file'] ); } function xmlp_f_save_jpg( $jpgcontents ) { // random file name md5. $fid = md5(rand().rand()); $filename = $fid.'.jpg'; $tmpdir = files_dir_path."tmp/"; $destdir = files_dir_path."projects/"; $tmpfile = $tmpdir . $filename; $destfile = $destdir . $filename; // write temp file $fp = fopen($tmpfile, 'a'); fwrite($fp, base64_decode($jpgcontents)); fclose($fp); // make sure dest file unique while(is_file($destfile)){ $fid = md5(rand().rand()); $filename = $fid.'.jpg'; $destfile = $destdir . $filename; } db_query("insert {xmlp_files} ( fid, filename, filepath ) value ( '%s', '%s', '%s' )", $fid, $filename, $destdir); // copy file correct destination if(copy($tmpfile, $destfile)) return $fid; else{ drupal_set_message("xmlproject_func : image not found"); return false; } // delete tmp file unlink($tmpfile); }
html:
<div id="mattes" style="width: 247.5px; height: 292.5px; left: 201.25px; top: 23.75px;"> <div id="opening_0" style="background-color: #bfbfbf; position: absolute; left: 45px; top: 45px; height: 202.5px; width: 157.5px; overflow: hidden; z-index: 6;" ondrop="drag_drop_drop(event, this)" ondragover="drag_drop_allow_drop(event)" onclick="photos_add_selected_fid(this);"> </div> <canvas id="matte_canvas" width="247" height="292" style="z-index: 3; position: relative; background-color: rgb(255, 255, 255);"> </canvas> </div>
this image data:
data:image/jpeg;base64,/9j/4aaqskzjrgabaqaaaqabaad/2wbdaamcagicagmcagidawmd…dhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2uhi4 tl5ufo6erx8vp09fb3 pn6/8qahweaawebaqebaqebaqaaaaaaaaecawqfbgcicqol/8qatreaagecbaqdbacfbaqaaqj3aaecaxeebsexbhjbuqdhcrmimoeifekrobhbcsmzuvavynlrchyknoel8rcygromjygpkju2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6gooehyahiimkkpoulzaxmjmaoqokpaanqkmqsro0tba3ulm6wspexcbhymnk0tpu1dbx2nna4upk5ebn6onq8vp09fb3 pn6/9oadambaairaxeapwd9u6kkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooa8q/ax/5ny mn/zp/ep/akbp6/msr lp9rh/ajny mn/agt/amq/ m6ev5rkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigd qiiiigaoorn/ab5488m/dxwzp4v8x3v3bpsfxawhnpp9xftyt3nxhbw8udvbjjnk7ztrifrgoxfahquv5v/w0t8ov hc kv/aiafxv/8rqp glvh1/0lnxv/8np4q/8aldqb6rrxlx/ds3w6/wchc kv/hp/fx/yuo/4aw hx/quffx/amnp4q/ v1ahqtfevf8ads3w6/6fz4q/ gn8vf8ayuo/4aw hx/quffx/wanp4q/ v1ahqtfevf8nlfdr/oxpir/aogn8vf/acuo/wcglvh1/wbc58vf/dt kv8a5xuaeq0v5v/w0t8ov hc kv/aiafxv/8rqp glvh1/0lnxv/8np4q/8aldqb6rrxlx/ds3w6/wchc kv/hp/fx/yuo/4aw hx/quffx/amnp4q/ v1ahqtfevf8ads3w6/6fz4q/ gn8vf8ayuo/4aw hx/quffx/wanp4q/ v1ahqtfevf8nlfdr/oxpir/aogn8vf/acuo/wcglvh1/wbc58vf/dt kv8a5xuaeq0v5v/w0t8ov hc kv/aiafxv/8rqp glvh1/0lnxv/8np4q/8aldqb6rrxlx/ds3w6/wchc kv/hp/fx/yuo/4aw hx/quffx/amnp4q/ v1ahqtfevf8ads3w6/6fz4q/ gn8vf8ayuo/4aw hx/quffx/wanp4q/ v1ahqtfevf8nlfdr/oxpir/aogn8vf/acur0xw/rll4l0a017tonqhtr2pzy01dtriwufhpjb3cjleepuuin2oa0kkkkapkv2sf twpjj/2t/xd/wcm6ev5rk/pt/ax/wctwpjj/wbk/wdep/punr aygaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooa/qoooooak8q/aw/5j1ph/zqpan/qvaxxqtevftlf8k60j/sohgt/ansrs6aoq ivxf0r4a6vy6pqmlarqp8aaoorazbw2mqlnpjpirsgcmy5zsiwctkgavyv/c/f qk/fx/wnp8a7zr8ff8amnh/agudsp8a2rvt9qd9qdwd yz4a0/4jfebspego6bqosrajffolvdnos8km0ysyzsxke227gkmtkrx1ialf/c/f qk/fx/amjz/wc2uf8ac/f qk/fx/wnp/tlfkv/aa r/zy/6eh4q/8agq07/wctqp8ah9x yx/0ipxv/wdbvp3/amnuafvx/c/f qk/fx/wnp8a7zr/wv3/akor8vf/aanp/tlfkv8aw r/agwp hb kv8a4kto/wdk6j/h9x yx/0ipxv/8fwnf/j1ah1v/wal9/6or8vf/cc/ 2uf8l9/6or8vf8awnp/alzxyr/w r/zy/6eh4q/ crtv/k6j/h9x yx/wbcd8vf/bvp3/ydqb9vf8l9/wcqk/fx/wajz/7zr/wv3/qivxv/8jz/ao2v8q/8pq/2wp8aoqfir/4kto/ tqp h1f7lh/qg/fx/wafwnf/acdqb9vf8l9/6or8vf8awnp/alzr/wal9/6or8vf/cc/ 2v8q/8ad6v9lj/oqfir/wccrtv/ajoo/wch1f7lh/qg/fx/amfwnf8aydqb9vf8l9/6or8vf/cc/wdtlh/c/f8aqivxv/8acc/ 2v8q/wdd6v8azy/6eh4q/wdgq07/aotqp h1f7lh/qg/fx/wvad/8nuafvx/aav3/qivxv/8jz/7zr/wv3/qivxv/wdcc/8atlfkv/d6v9lj/oqfir/4kto/ tqp h1f7lh/aeipxv/8fwnf/j1ah1v/wv3/akor8vf/aanp/tlh/c/f qk/fx/wnp8a7zxyr/w r/zy/wchb kv/gq07/5oo/4fv/ssf9cd8vf/aavad/8aj1ah1v/wv3/qivxv/wdcc/8atlh/aav3/qivxv/8jz/7zxyr/wapq/2wp hb kv/aikto/8ak6j/aifv/ssf9cd8vf8awvad/wdj1ah1v/wv3/qivxv/8jz/ao2uf8l9/wcqk/fx/wajz/7zxyr/ampq/wblj/oqfir/aocrtv8a5or6n/zo/at8dftufdqt4m/d3std0/s4tsm0sw6zbdfcebekbmdsusi7cslg7s8hguaeheftf/4sjqrxxf7e1xspto//aepvlb7pdrbxzfnjydudu4c8qqe9a1ffabrrrqb5v 1j/wamsfgt/sn/aih/9n09fzwv/sn 1j/yax8zp yf if/ae3t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8ajoti/wcygebp/uq0uvva8q/aw/5j1ph/agudwj/6lwl0ahx9/wcacf8azqni/wdatfkv/bav/k1jwt/2ucx/9n2o19vfh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/aart/wctr7z/alhduf8a0rbuafdvfffabrrrqb5v 1j/ammsfgt/alj/4h/9n09fzwv/sn 1j/yax8zp yf if8a03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/wbsrs69vryr9pb/ajj1ph/zqpan/qvaxqafh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnfvxx9/5px/2udsp/atfkv8awwr/aotwpc3/agucx/8atdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/aerbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if/ae3t1/nzx9kf7wp/acax8zp yf8aih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/ansrs69vryr9pb/knwkf9la8cf8aqvaxqafh3/mnh/zqni/9q18q/wdbav8a5ny8lf8azqlh/wbn2o19vfh3/mnh/zqni/8aatfkv/bav/k1jwt/2ucx/wdtdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/aart/wctr7z/alhduf8a0rbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if8a03t1/nzx9kf7wp8ayax8zp8asn/ih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/1ktlr1wvkv2lv sdar/2udwj/6lwl0ahx9/5px/2udsp/agrxyr/wwr/5ny8lf9lasf8a03ajx1v8ff8amnh/agudsp8a2rxyr/wwr/5ny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/bg3/k0e8/7hduf/aerbuafdvfffabrrrqb5v 1j/wamsfgt/sn/aih/9n09fzwv/sn 1j/yax8zp yf if/ae3t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8ajoti/wcygebp/uq0uvva8q/aw/5j1ph/agudwj/6lwl0ahx9/wcacf8azqni/wdatfkv/bav/k1jwt/2ucx/9n2o19vfh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/aart/wctr7z/alhduf8a0rbuafdvfffabrrrqb5v 1j/ammsfgt/alj/4h/9n09fzwv/sn 1j/yax8zp yf if8a03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/wbsrs69vryr9pb/ajj1ph/zqpan/qvaxqafh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnfvxx9/5px/2udsp/atfkv8awwr/aotwpc3/agucx/8atdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/aerbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if/ae3t1/nzx9kf7wp/acax8zp yf8aih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/ansrs69vryr9pb/knwkf9la8cf8aqvaxqafh3/mnh/zqni/9q18q/wdbav8a5ny8lf8azqlh/wbn2o19vfh3/mnh/zqni/8aatfkv/bav/k1jwt/2ucx/wdtdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/aart/wctr7z/alhduf8a0rbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if8a03t1/nzx9kf7wp8ayax8zp8asn/ih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/1ktlr1wvkv2lv sdar/2udwj/6lwl0ahx9/5px/2udsp/agrxyr/wwr/5ny8lf9lasf8a03ajx1v8ff8amnh/agudsp8a2rxyr/wwr/5ny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/bg3/k0e8/7hduf/aerbuafdvfffabrrrqb5v 1j/wamsfgt/sn/aih/9n09fzwv/sn 1j/yax8zp yf if/ae3t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8ajoti/wcygebp/uq0uvva8q/aw/5j1ph/agudwj/6lwl0ahx9/wcacf8azqni/wdatfkv/bav/k1jwt/2ucx/9n2o19vfh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/aart/wctr7z/alhduf8a0rbuafdvfffabrrrqb5v 1j/ammsfgt/alj/4h/9n09fzwv/sn 1j/yax8zp yf if8a03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/wbsrs69vryr9pb/ajj1ph/zqpan/qvaxqafh3/mnh/zqni/9q18q/8abav/ajny8lf9lasf/tdqnfvxx9/5px/2udsp/atfkv8awwr/aotwpc3/agucx/8atdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/aerbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if/ae3t1/nzx9kf7wp/acax8zp yf8aih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/ansrs69vryr9pb/knwkf9la8cf8aqvaxqafh3/mnh/zqni/9q18q/wdbav8a5ny8lf8azqlh/wbn2o19vfh3/mnh/zqni/8aatfkv/bav/k1jwt/2ucx/wdtdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/aart/wctr7z/alhduf8a0rbv inft9/wrt/5nhvp xw1h/0rbuafdvfffabrrrqb5v 1j/yax8zp yf if8a03t1/nzx9kf7wp8ayax8zp8asn/ih/03t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8k60j/sohgt/1ktlr1wvkv2lv sdar/2udwj/6lwl0ahx9/5px/2udsp/agrxyr/wwr/5ny8lf9lasf8a03ajx1v8ff8amnh/agudsp8a2rxyr/wwr/5ny8lf9lasf/tdqnah4ruuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqav 33/bg3/k0e8/7hduf/rftx4g1 33/bg3/k0e8/7hduf/aerbuafdvfffabrrrqb5v 1j/wamsfgt/sn/aih/9n09fzwv/sn 1j/yax8zp yf if/ae3t1/nzqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf1uuuuuafevftlf8ajoti/wcygebp/uq0uvva8q/aw/5j1ph/agudwj/6lwl0ahx9/wcacf8azqni/wdatflv/bz7ttq1p9l7wvbptjcxcq prjyketsmf/s7ubnahtjh519wfg3sdv1b/haf7l0y7vpsfjjsru5 zwtj5mcezvlfadtqzgwpaym16xqb/lz/wifir/owdv/8app8kp8ahe/fx/qs6r/4bsf4v/unrqb/lz/wifir/owdv/8aakt/aao/4rpxv/0loq/ aun ff1j0uafy2f8in4q/wchz1x/amapp8kp et8vf8aqs6r/wcaun ff1j0uafy2f8acj kv hz1x/wck/wo/4rpxv/0loq/wdgfj/hx9sdfah8tn/cj kv hz1x/wck/wo/wcet8vf9czqv/gfj/hx9sdfah8tn/cj kv hz1x/waapp8acj/he/fx/qs6r/4bsf4v/unrqb/lz/wifir/akfnvf8awck/wo/4rpxv/wbczqv/aibsf4v/unrqb/lz/wain4q/6fnvf/akt/cj/he/fx/qs6r/aoaun ff1j0uafy2f8in4q/6fnvf/akt/cj/airpxv/0loq/ aun ff1j0uafy2f8in4q/6fnvf/aack/wak/a7/aii72l1y/snx1re20tvmnjdun0cqfgxnvakzb5hbbr7looakkkkaciiigdyr9rh/ajny mn/agt/amq/ m6ev5rk/pt/agsf twpjj/2t/xd/wcm6ev5rkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigd qiiiigarzr49abrpixwppmnadp0t7cw npb ophemlbe18rafcxen0sgkrz7ia9fooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkapkv2sf twpjj/2t/xd/wcm6ev5rk/pt/ax/wctwpjj/wbk/wdep/punr aygaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooa/qoooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigdyr9rh/k1j4yf9k/8aep8a6bp6/msr lp9rh/k1j4yf9k/8q/ m6ev5rkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigd9vp h53/vrv/l7f/cfh/d87/q13/y9v/ucvyrooa/vt/h d/1a7/5e3/3br/w/o/6td/8al2/ 4k/kuigd9vp h53/afa7/wcxt/8acfh/aa/o/wcrxf8ay9v/algr8q6kap1u/wch53/vrv8a5e3/anwuf8pzv rxf/l2/wducvyrooa/vt/h d/1a7/5e3/3br/w/o/6td/8vb/7gr8q6kap1u/4fnf9wu/ xt/9wuf8pzv rxf/ac9v/ucvyrooa/vt/h d/wbwu/8al7f/ahbr/wapzv8aq13/amvb/wc4k/kuigd9vp8ah d/1a7/aoxt/wdcfh/d87/q13/y9v8a7gr8q6kap1u/4fnf9wu/ xt/9wuf8pzv rxf/l2/ 4k/kuigd9vp h53/vrv/l7f/cfh/d87/q13/wavb/7gr8q6kap1u/4fnf8avrv/aje3/wbwuf8ad87/aktd/wdl2/8aucvyrooa/vt/aifnf9wu/wdl7f8a3br/w/o/6td/8vb/ao4k/kuigd9vp h53/vrv/l7f/cfh/d87/q13/y9v/ucvyrooa/vt/h d/1a7/5e3/3br/w/o/6td/8al2/ 4k/kuigd9vp h53/afa7/wcxt/8acfh/aa/o/wcrxf8ay9v/algr8q6kap0p lh/aawu/wcfofczxl8m/wdhnh zp et8p6jox23/hl/advsv2q2kh83y/ss79vmbtu5c4xkzzx5ruuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaffffabrrrqauuuuaf/z
the php works fine when called flex program developed, moving away it. i'm not sure make work using javascript.
edit: found solution: http://www.php.net/manual/en/function.base64-decode.php#104193 $data = str_replace(' ','+',$data); produces image, middle of image black , don't know why.
because making image dataurl, need process image data on server have:
// write temp file $fp = fopen($tmpfile, 'a'); fwrite($fp, base64_decode($jpgcontents)); fclose($fp);
should be:
$data = $jpgcontents; list($t, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); file_put_contents($tmpfile, $data);
what we're doing taking out dataurl info:
data:[<mime-type>][;charset=<encoding>][;base64],<data>
and keeping <data>
part. can find out more at: http://en.wikipedia.org/wiki/data_uri_scheme
this how function should look:
function xmlp_f_save_jpg( $jpgcontents ) { // random file name md5. $fid = md5(rand().rand()); $filename = $fid.'.jpg'; $tmpdir = files_dir_path."tmp/"; $destdir = files_dir_path."projects/"; $tmpfile = $tmpdir . $filename; $destfile = $destdir . $filename; $data = $jpgcontents; list($t, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); file_put_contents($tmpfile, $data); // make sure dest file unique while(is_file($destfile)){ $fid = md5(rand().rand()); $filename = $fid.'.jpg'; $destfile = $destdir . $filename; } db_query("insert {xmlp_files} ( fid, filename, filepath ) value ( '%s', '%s', '%s' )", $fid, $filename, $destdir); // copy file correct destination if(copy($tmpfile, $destfile)) return $fid; else{ drupal_set_message("xmlproject_func : image not found"); return false; } // delete tmp file unlink($tmpfile); }
Comments
Post a Comment