$(function () {
var myForm = $('form');
myForm.on('submit', function() {
$.ajax(
// Тут отправляем AJAX запрос, очищаем поле, вставляем сообщение в чат и т.д.
);
// Чтоб страница не перезагрузилась
return false;
});
$("#chatbot-submit").on('click', function() {
myForm.submit();
});
});
<script>
$(function () {
$('form').submit(function( event ) {
var data = $(this).serialize().replace(/[^&]+=&/g, '').replace(/&[^&]+=$/g, '');
$.ajax({
type: 'GET',
url: '/search'+data,
data: data,
success: function(output, status, xhr) {
history.pushState({foo: 'bar'}, 'title', '/search'+data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + thrownError);
}
});
return false;
});
});
</script>
history.pushState({foo: 'bar'}, 'title', this.url);
if (isset($_FILES)){
foreach ($_FILES['uploadfile']['name'] as $k=>$v){
if($_FILES['uploadfile']['type'][$k] == "image/gif" || $_FILES['uploadfile']['type'][$k] == "image/png" || $_FILES['uploadfile']['type'][$k] == "image/jpg" || $_FILES['uploadfile']['type'][$k] == "image/jpeg"){
$blacklist = array(".php", ".phtml", ".php3", ".php4");
foreach ($blacklist as $item){
if(preg_match("/$item\$/i", $_FILES['uploadfile']['name'][$k])){
echo "Нельзя загружать скрипты.";
exit;
}
}
# сюда загружается файл на основном сервере
$file = $_FILES['uploadfile']['tmp_name'][$k];
# адрес сервера
$url = 'http://s1.site.ru/upload.php';
$post = [
'image'=> new CURLFile($file, mime_content_type($file), date('YmdHis').rand(100,1000)),
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
}
}
}
<?php
class Cache
{
private $memcache;
public function __construct()
{
if (extension_loaded('memcache'))
{
$this->memcache = new Memcache();
$this->memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
}
}
public function __destruct()
{
$this->memcache->close();
}
public function save($key, $data, $time = 0)
{
$this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $time);
}
public function load($key)
{
$get_result = $this->memcache->get($key);
return $get_result;
}
public function delete($key)
{
$this->memcache->delete($key);
}
public function clear()
{
$this->memcache->flush();
}
public static function make(Closure $object, $time, $key){
$cache = new Cache();
if (!$cacheData = $cache->load($key)){
$object = is_callable($object) ? call_user_func($object):$object;
$cache->save($key, $object, $time);
return $object;
}
else
{
return $cacheData;
}
}
}
// Cache::make($value, $time, $key);
$data = Cache::make(function(){
return DB::from("users")->orderBy("name DESC")->paginate(28)->fetchAll();
}, 5, md5($_SERVER['REQUEST_URI']) );