io ho proposto ajax per non passare il codice tramite get direttamente al popup...
allora ecco i codici (sono troppo buono):
SCRIPT JS che richiama un file in php e poi apre un popup
Codice HTML:
function submit(FILE, METHOD)
{
var target = '';
var rnd = Math.random();
var num = document.forms[0].elements.length;
var url = "";
for (var i = 0; i < num; i++)
{
var chiave = document.forms[0].elements[i].name;
var valore = document.forms[0].elements[i].value;
var tipo = document.forms[0].elements[i].type;
if ( (tipo != "submit") && (tipo != "radio") && (tipo != "checkbox") )
{
url += chiave + "=" + valore + "&";
}
}
var parameters = url;
url = FILE + "?" + url + "rnd" + rnd;
if (METHOD == undefined)
{
METHOD = "GET";
}
if (METHOD == "GET")
{
ahah(url, target, '', METHOD);
}
else
{
ahah(FILE, target, '', METHOD, parameters);
}
}
function ahah(url, target, delay, method, parameters)
{
if (method == undefined)
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req)
{
req.onreadystatechange = function()
{
//ahahDone(url, target, delay, method, parameters);
if (req.readyState == 4)
{
if (req.status == 200)
{
response = req.responseText;
}
}
};
req.open("GET", url, true);
req.send("");
}
}
if ( (method == "GET") || (method == "get") )
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req)
{
req.onreadystatechange = function()
{
//ahahDone(url, target, delay, method, parameters);
if (req.readyState == 4)
{
if (req.status == 200)
{
response = req.responseText;
}
}
};
req.open(method, url, true);
req.send("");
}
}
if ( (method == "POST") || (method == "post") )
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
} else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req)
{
req.onreadystatechange = function()
{
//ahahDone(url, target, delay, method, parameters);
if (req.readyState == 4)
{
if (req.status == 200)
{
response = req.responseText;
}
}
};
req.open(method, url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send(parameters);
}
}
//return response;
}
function ahahDone(url, target, delay, method, parameters)
{
if (req.readyState == 4)
{
if (req.status == 200)
{
window.open('file.php?file=' + req.responseText,'Codice','width=500,height=500,scrollbar);
}
}
}
Form con la textarea:
Codice HTML:
<form action="" method="post">
<textarea name="codice"></textarea>
<input type="button" name="invia" value="Visualizza codice" onclick="submit('scrivi.php', 'POST')">
</form>
file scrivi.php
Codice PHP:
<?
function random($dir)
{
$rand = rand(0, 15000);
$file = 'fileid' . $rand . '.txt';
if( file_exists($dir . $file) )
{
random($dir)
}
else
{
return $rand;
}
}
$dir = 'cartella/';
$rand = random($dir);
$path = 'fileid' . $rand . '.txt';
$fp = fopen($path, 'w+');
if( fwrite($fp, $_POST['codice']) )
{
echo $rand;
}
fclose($fp);
?>
file file.php
Codice PHP:
<?
$dir = 'cartella/';
$file = $dir . 'fileid' . $_GET['file'] . '.txt';
$code = hightlight_file($file);
echo $code;
?>
Naturalmente i codici non li ho provati