Page 1 of 1

Try to fwrite javascript code to a file

Posted: Tue Apr 06, 2010 10:22 am
by Partyzan
Hey,
I have problems writing to a file, the php just won't run.
This is the problamaric line:

Code: Select all

fwrite($fh, "<script language='JavaScript'><!--function FP_swapImg() {//v1.0 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length; n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm; elm.$src=elm.src; elm.src=args[n+1]; } }}function FP_preloadImgs() {//v1.0 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array(); for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }}function FP_getObjectByID(id,o) {//v1.0 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id); else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el; if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c) for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; } f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements; for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } } return null;}// --></script></head><body topmargin='0' bottommargin='0' onload='FP_preloadImgs(/*url*/'../button81.gif',/*url*/'../button7F.gif',/*url*/'../button5C.gif',/*url*/'../button5B.gif',/*url*/'../button3F1.gif',/*url*/'../button3E1.gif',/*url*/'../button47.gif',/*url*/'../button46.gif',/*url*/'../button49.gif',/*url*/'../button48.gif',/*url*/'../button3.gif',/*url*/'../button2.gif')'><div style='position: absolute; width: 1118px; height: 1193px; z-../index: 1; right: -3px; top: 1px' id='layer26'><img border='0' src='../index11.jpg'>&nbsp;</div>	<div style='position: absolute; width: 1022px; height: 1205px; z-../index: 2; right: 7px; top: -12px' id='layer34'>		<div style='position: absolute; width: 100px; height: 100px; z-../index: 8; right: 169px; top: 22px' id='layer27'><div style='position: absolute; width: 836px; height: 995px; z-../index: 5; right: -23; top: 178px; visibility: visible' id='layer5'>	<div style='position: absolute; width: 775px; height: 33px; z-../index: 16; right: 22px; top: 0px' id='layer27'>		<div style='position: absolute; width: 75px; height: 24px; z-../index: 1; right: -26px; top: -1px' id='layer28'>	<a href='http://www.2ride.co.il/'>	<img border='0' id='img28' src='../button7E.gif' height='25' width='75' alt='&#1488;&#1493;&#1508;&#1504;&#1497;&#1497;&#1501; &#1495;&#1513;&#1502;&#1500;&#1497;&#1497;&#1501;' onmouseover='FP_swapImg(1,0,/*id*/'img28',/*url*/'../button7F.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img28',/*url*/'../button7E.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img28',/*url*/'../button81.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img28',/*url*/'../button7F.gif')' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFFFF; fp-transparent: 1; fp-proportional: 0; fp-orig: 0' fp-title='&#1512;&#1488;&#1513;&#1497;'></a></div>		<div style='position: absolute; width: 130px; height: 21px; z-../index: 2; right: 60px; top: -1px' id='layer29'>	<a href='http://www.2ride.co.il/how-it-works.htm'>	<img border='0' id='img27' src='../button5A.gif' height='25' width='130' alt='&#1488;&#1497;&#1498; &#1494;&#1492; &#1506;&#1493;&#1489;&#1491;?' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFFFF; fp-transparent: 1; fp-proportional: 0; fp-orig: 0' fp-title='&#1488;&#1497;&#1498; &#1494;&#1492; &#1506;&#1493;&#1489;&#1491;?' onmouseover='FP_swapImg(1,0,/*id*/'img27',/*url*/'../button5B.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img27',/*url*/'../button5A.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img27',/*url*/'../button5C.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img27',/*url*/'../button5B.gif')'></a></div>		<div style='position: absolute; width: 125px; height: 24px; z-../index: 3; right: 214px; top: -1px' id='layer30'>	<a href='http://www.2ride.co.il/order.htm'>	<img border='0' id='img23' src='../button3D1.gif' height='25' width='125' alt='&#1495;&#1493;&#1511;&#1497; &#1489;&#1497;&#1513;&#1512;&#1488;&#1500;' onmouseover='FP_swapImg(1,0,/*id*/'img23',/*url*/'../button3E1.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img23',/*url*/'../button3D1.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img23',/*url*/'../button3F1.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img23',/*url*/'../button3E1.gif')' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFFFF; fp-transparent: 1; fp-proportional: 0; fp-orig: 0' fp-title='&#1495;&#1493;&#1511;&#1497; &#1489;&#1497;&#1513;&#1512;&#1488;&#1500;'></a></div>		<div style='position: absolute; width: 125px; height: 16px; z-../index: 4; right: 363px; top: -1px' id='layer31'>	<a href='http://www.2ride.co.il/green-tendency.htm'>	<img border='0' id='img24' src='../button52.gif' height='25' width='125' alt='&#1502;&#1490;&#1502;&#1492; &#1497;&#1512;&#1493;&#1511;&#1492;' onmouseover='FP_swapImg(1,0,/*id*/'img24',/*url*/'../button46.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img24',/*url*/'../button52.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img24',/*url*/'../button47.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img24',/*url*/'../button46.gif')' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFFFF; fp-transparent: 1; fp-orig: 0' fp-title='&#1502;&#1490;&#1502;&#1492; &#1497;&#1512;&#1493;&#1511;&#1492;'></a></div>		<div style='position: absolute; width: 130px; height: 20px; z-../index: 5; right: 512px; top: -1px' id='layer32'>	<a href='http://www.2ride.co.il/electric-bike-kit.htm'>	<img border='0' id='img25' src='../button53.gif' height='25' width='130' alt='&#1514;&#1499;&#1493;&#1500;&#1514; &#1492;&#1506;&#1512;&#1499;&#1492;' onmouseover='FP_swapImg(1,0,/*id*/'img25',/*url*/'../button48.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img25',/*url*/'../button53.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img25',/*url*/'../button49.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img25',/*url*/'../button48.gif')' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFFFF; fp-transparent: 1; fp-proportional: 0; fp-orig: 0' fp-title='&#1514;&#1499;&#1493;&#1500;&#1514; &#1492;&#1506;&#1512;&#1499;&#1492;'></a></div>		<div style='position: absolute; width: 44px; height: 16px; z-../index: 6; right: 666px; top: -1px' id='layer33'>			<a href='http://www.2ride.co.il/buy-electric-bike.htm'>	<img border='0' id='img29' src='../button1.gif' height='25' width='90' alt='&#1500;&#1492;&#1494;&#1502;&#1504;&#1493;&#1514;' fp-style='fp-btn: Simple Text 4; fp-font: Arial; fp-font-size: 17; fp-font-color-normal: #FFFF00; fp-transparent: 1; fp-proportional: 0; fp-orig: 0' fp-title='&#1500;&#1492;&#1494;&#1502;&#1504;&#1493;&#1514;' onmouseover='FP_swapImg(1,0,/*id*/'img29',/*url*/'../button2.gif')' onmouseout='FP_swapImg(0,0,/*id*/'img29',/*url*/'../button1.gif')' onmousedown='FP_swapImg(1,0,/*id*/'img29',/*url*/'../button3.gif')' onmouseup='FP_swapImg(0,0,/*id*/'img29',/*url*/'../button2.gif')'></a></div>		<p>&nbsp;</div>	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	<span style='text-decoration: none'>	&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp; 	<div style='position: absolute; width: 210px; height: 28px; z-../index: 19; right: 576px; top: 957px' id='layer41'>		<font face='Arial' style='font-size: 11pt'>&#1495;&#1494;&#1512;&#1492; &#1500;&#1491;&#1507;		<a href='http://www.2ride.co.il/' style='text-decoration: none'>&#1488;&#1493;&#1508;&#1504;&#1497;&#1497;&#1501; 		&#1495;&#1513;&#1502;&#1500;&#1497;&#1497;&#1501;</a></font></div>	<div style='position: absolute; width: 661px; height: 624px; z-../index: 18; right: 20px; top: 127px' id='layer40'><span lang='en-us'>");
I tried to solve it myself, googled it and didn't find an answer!
Please help :)

Re: Try to fwrite javascript code to a file

Posted: Tue Apr 06, 2010 10:48 am
by AbraCadaver
It's a problem with this:

Code: Select all

$imgSwaps[doc.$imgSwaps.length]
PHP is treating this as a PHP array item. Try concatenating your PHP vars like so:

Code: Select all

"<script language='JavaScript'><!--function FP_swapImg() {//v1.0 var doc=document,args=arguments,elm,n; doc." . $imgSwaps . "=new Array(); for(n=2; n<args.length; n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc." . $imgSwaps . "[doc." . $imgSwaps . ".length]=elm;";

Re: Try to fwrite javascript code to a file

Posted: Tue Apr 06, 2010 10:54 am
by Partyzan
Thank you very much sir!