expmail/helpers.php

25 lines
No EOL
863 B
PHP

<?php
function getFilename($url){
$content = get_headers($url,1);
$content = array_change_key_case($content, CASE_LOWER);
if ($content['content-disposition']) {
$tmp_name = explode('=', $content['content-disposition']);
if ($tmp_name[1]) $realfilename = trim($tmp_name[1],'";\'');
} else {
$stripped_url = preg_replace('/\\?.*/', '', $url);
$stripped_url = preg_replace('/\\/$/', '', $stripped_url);
$realfilename = basename($stripped_url);
}
return $realfilename;
}
function checkURL($url) {
$url = filter_var($url, FILTER_SANITIZE_URL);
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE || !in_array(strtolower(parse_url($url, PHP_URL_SCHEME)), ['http','https'], true)) return false;
$file_headers = @get_headers($url);
if ($httpStatus<400) return true;
return false;
}