Php pozvan iz js

<?php // Programer: Davor Bergam 2006. Header("content-type: application/x-javascript"); $fl = "br.txt"; $ds=filesize($fl); $fh = fopen($fl, 'r') or die; $br = fread($fh,$ds); fclose($fh); for ($i=0;$i<$ds;$i++) { $zn=substr($br,$i,1); $po=substr($br,$i+1,$ds); if ($po==0) $fld="ani"; else $fld="sta"; echo "document.write('')"; } ?>

Gornja skripta se poziva iz HTML-a donjim tagom. Nemam nikakav output. Može pomoć?

Napomena: Ako umjesto poziva iz HTML-a pozivam iz php dokumenta sa include onda radi uz malu izmjenu patheva prema txt fileu.

Dodatak: I naravno u slučaju kad se poziva iz php nema document.write već samo echo

Ne radi nikako. Zaboravite!! Ovo je i tako bio test.

vjerovatno JS poziv ne parsira PHP fajl…

I šta učiniti u tom slučaju?

  1. Provjeri putanje datoteka (pogotovo onu putanju unutar .php datoteke)
  2. Pokušaj izbaciti Header iz .php datoteke

Ovaj kod radi:<span class="syntaxdefault"><?php<br /></span><span class="syntaxcomment">//&nbsp;Programer:&nbsp;Davor&nbsp;Bergam&nbsp;2006.<br /></span><span class="syntaxdefault">$niz</span><span class="syntaxkeyword">=</span><span class="syntaxstring">""</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$fl&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"br.txt"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$ds</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">filesize</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$fl</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">$fh&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">fopen</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$fl</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxstring">'r'</span><span class="syntaxkeyword">)&nbsp;or&nbsp;die;<br /></span><span class="syntaxdefault">$br&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">fread</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$fh</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$ds</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">fclose</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$fh</span><span class="syntaxkeyword">);<br />for&nbsp;(</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword"><</span><span class="syntaxdefault">$ds</span><span class="syntaxkeyword">;</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">++)<br />{<br /></span><span class="syntaxdefault">$zn</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">substr</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$br</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">$po</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">substr</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$br</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">);<br />if&nbsp;(</span><span class="syntaxdefault">$po</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">$fld</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"ani"</span><span class="syntaxkeyword">;<br />else&nbsp;</span><span class="syntaxdefault">$fld</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"sta"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$d</span><span class="syntaxkeyword">=</span><span class="syntaxstring">"<img&nbsp;src=brojac/"</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$fld</span><span class="syntaxkeyword">.</span><span class="syntaxstring">"/"</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$zn</span><span class="syntaxkeyword">.</span><span class="syntaxstring">".gif>"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$niz</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$niz</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$d</span><span class="syntaxkeyword">;<br />}<br />echo&nbsp;</span><span class="syntaxstring">"document.write('"</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$niz</span><span class="syntaxkeyword">.</span><span class="syntaxstring">"')"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">?></span>

možeš koristiti i driname(FILE) da dobiš pravu putanju filea, tada ne igra uoppće ulogu dali je fajl includean u neku skriptu, ili pozvan direktno

[quote=“Gigolo”]<?php
// Programer: Davor Bergam 2006.
Header(“content-type: application/x-javascript”);
$fl = “br.txt”;
$ds=filesize($fl);
$fh = fopen($fl, ‘r’) or die;
$br = fread($fh,$ds);
fclose($fh);
for ($i=0;$i<$ds;$i++)
{
$zn=substr($br,$i,1);
$po=substr($br,$i+1,$ds);
if ($po==0)
$fld=“ani”;
else $fld=“sta”;
echo “document.write(’<img src=”.$fld."/".$zn.".gif>’)";
}
?>
Gornja skripta se poziva iz HTML-a donjim tagom. Nemam nikakav output. Može pomoć?

Napomena: Ako umjesto poziva iz HTML-a pozivam iz php dokumenta sa include onda radi uz malu izmjenu patheva prema txt fileu.[/quote]

  1. imas krivi “Content-type”
  2. “document.write” se moze pozivati prije ucitavanja kompletnog HTML-a ~ unutar body taga (a mislim da ga ti pozivas nakon i zbog toga ti ne bi trebao raditi)
  3. language=“JavaScript” nije potreban

Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja