Архив

Архив раздела ‘PHP’
14 августа 2018 Нет комментариев
function correct_image_orientation($filename,$quality=100){
	if(function_exists('exif_read_data')){
		$exif=exif_read_data($filename);
		if($exif&&isset($exif['Orientation'])){
			$angles=array(3=>180,6=>270,8=>90);
			if(isset($angles[$exif['Orientation']])){
				$image=imagecreatefromjpeg($filename);
				$image=imagerotate($image,$angles[$exif['Orientation']],0);
				imagejpeg($image,$filename,$quality);
			}
		}
	}
}

Использование:

move_uploaded_file($file['tmp_name'],ROOT_DIR.IMAGES_PHOTOS_DIR.$fname);
correct_image_orientation(ROOT_DIR.IMAGES_PHOTOS_DIR.$fname);
Categories: PHP Tags:
parse_url($_SERVER['HTTP_REFERER'],PHP_URL_HOST)
Categories: PHP Tags:
if($_SERVER['HTTP_X_REQUESTED_WITH']=='com.example.app'){
	echo 'Это мое приложение, а не мобильный браузер';
}

com.example.app — имя нашего пакета

Categories: Android, PHP Tags: ,
20 ноября 2017 Нет комментариев
$timeout=15;
$client=new SoapClient("http://host.com/service.asmx?WSDL",array('connection_timeout'=>$timeout));
Categories: PHP Tags:
20 ноября 2017 Нет комментариев
$timeout=15;
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);
Categories: PHP Tags:
16 ноября 2017 Нет комментариев

Нужно используя CURL просто получить URL перенаправления, но не переходить по нему внутри CURL.

$post_fields=array(
	"field1"=>$value1,
	"field2"=>$value2,
);
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,'https://site.ru/path/');
curl_setopt($curl,CURLOPT_HEADER,1);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post_fields);
$res=curl_exec($curl);
curl_close($curl);
preg_match_all('/^Location:(.*)$/mi',$res,$matches);
if(!empty($matches[1])){
	header("Location: ".trim($matches[1][0]),true,301);
}
exit();
Categories: PHP Tags: ,
9 ноября 2017 Нет комментариев

При отправке писем, используя функцию php mail(), при появлении в сообщении в произвольных на первый взгляд местах символов "! " (восклицательный знак и пробел) — вручную добавить переносы строк:

$crlf="\r\n";
$message.='...text'.$crlf;

Проблема из-за ограничения длины строки (вероятно возможно где-то увеличить этот лимит, но надежнее добавить переносы строк, чтобы избежать проблем при переносе сайта на другой сервер с default настройками).

Categories: PHP Tags: