<?php
// defined($_POST['firstname']) or die('No direct access allowed.');
// можно ограничить домен, для которого доступен ответ
// header('Access-Control-Allow-Origin: http://javascript.ru');
header('Access-Control-Allow-Origin: http://blabla.bla');
$namedealer = $_POST['firstname'];
$dir = $namedealer.'/';
$files = scandir($dir);
readfile($files );
$summ = 0;
foreach (glob($dir . "*.txt") as $filename) {
$lines = file($filename);
$linesreplace = array("ИТОГО", "BYN");
$linesreplaceto = array("", "");
$newlines = str_replace($linesreplace, $linesreplaceto, $lines);
$arr = explode(' ', $newlines[0]);
$summ += $arr[1];
}
echo '<div class="itogo">Сумма итого: ' . $summ . ' BYN</div>';
echo '<ul class="styleaccord">';
foreach ($files as $value)
{
if ($value !='.' and $value !='..' )
{
$text=file_get_contents($dir.$value);
$text = preg_replace("/\n/", "<br/>\n", $text);
echo '<li>';
echo '<a href="#"><p>'.$value.'</p><p style="float: right;padding-right: 50px;">'.$arr.'</p><ins></ins></a>';
echo '<div style="display:none;"><div><p>'.$text.'</p></div></div>'; #выводим содержание
echo '</li>';
}
else{}
}
echo '</ul>';
?>
echo '<li>';
echo '<a href="#"><p>'.$value.'</p><p style="float: right;padding-right: 50px;">'.$firstext[0].'</p><ins></ins></a>';
echo '<div style="display:none;"><div><p>'.$text.'</p></div></div>'; #выводим содержание
echo '</li>';
...........
$files = scandir($dir);
readfile($files );
foreach (glob($dir . "*.txt") as $filename) {
$lines = file($filename);
$linesreplace = array("ИТОГО", "BYN");
$linesreplaceto = array("", "");
$newlines = str_replace($linesreplace, $linesreplaceto, $lines);
echo $newlines[0];
}
.......
echo $newlines[0];
$arr = explode(' ', $newlines[0]);
echo array_sum($arr);
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = 'upsend.php';
var fn = $('.g-user-info > span > span:eq(1)').text();
var vars = "firstname="+fn;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "Ожидайте...";
}