7 февраля 2020
Нет комментариев
.htacess:
Header set Access-Control-Allow-Origin *
или php:
header('Access-Control-Allow-Origin: *');
.htacess:
Header set Access-Control-Allow-Origin *
или php:
header('Access-Control-Allow-Origin: *');
ini_set('session.gc_maxlifetime',120960); ini_set('session.cookie_lifetime',120960); ini_set('session.save_path',$_SERVER['DOCUMENT_ROOT'].'../sessions/');
https://habr.com/ru/post/28418/
Javascript:
$(document).ready(function(){ var select_brand=$('select[name=brand]'); var select_collection=$('select[name=collection]'); select_brand.on('change',function(){ $.ajax({ url:"/?ajax_action=get_collections&brand="+select_brand.val(), dataType:"json", success:function(data){ select_collection.find('option').not(':first').remove(); $.each(data,function(index,item){ select_collection.append('<option value="'+item.id+'">'+item.name+'</option>'); }); select_collection.trigger("chosen:updated"); } }); }); });
HTML:
<select name="brand" class="chosen"> <option value="0">Выбрать</option> <?if(count($brands)>0){?> <?foreach($brands as $item){?> <option value="<?=$item['id']?>"<?if($item['id']==$change_catalog["brand"]){?> selected="selected"<?}?>><?=$item['name']?></option> <?}?> <?}?> </select> <select name="collection" class="chosen"> <option value="0">Выбрать</option> <?if(count($collections)>0){?> <?foreach($collections as $item){?> <option value="<?=$item['id']?>"<?if($item['id']==$change_catalog["collection"]){?> selected="selected"<?}?>><?=$item['name']?></option> <?}?> <?}?> </select>
PHP:
if($_GET['ajax_action']=='get_collections'&&$_GET['brand']>0){ header("Content-Type: application/json"); $result=get_from_base('`id`,`name`','collections',"`parent`='".$_GET['brand']."'",'pos'); echo json_encode($result); exit(); } $brands=get_from_base('`id`,`name`','brands',"1",'`parent`,`pos`'); if($_GET["change_id"]){ $change_catalog=get_by_id($_GET["change_id"],'catalog'); if($change_catalog['brand']){ $collections=get_from_base('`id`,`name`','collections',"`parent`='".$change_catalog['brand']."'",'pos'); } }
function simplexml_load_file_from_url($url,$timeout=60){ $opts=array('http'=>array('timeout'=>(int)$timeout)); $context=stream_context_create($opts); $data=file_get_contents($url,false,$context); if(!$data){ return false; } return simplexml_load_string($data); }
использовать вместо simplexml_load_file
Для автоматического создания папок при использовании file_put_contents
function save_to_dir($to,$content){ $path=pathinfo($to); if(!file_exists($path['dirname'])){ mkdir($path['dirname'],0777,true); } return file_put_contents($to,$content); }
$item['date']
— timestamp прошедшей даты
$date_today=strtotime(date('Y-m-d',time())); $sec_diff=$date_today-$item['date']; $date_diff=floor($sec_diff/(60*60*24));
Создавать целевую папку, если такая не существует перед копированием. Использовать вместо функции copy
:
function copy_to_dir($from,$to){ $path=pathinfo($to); if(!file_exists($path['dirname'])){ mkdir($path['dirname'],0777,true); } if(!copy($from,$to)){ return false; } return true; }