- var_dump: documentation ( source)
- dirname: documentation ( source)
- parse_url: documentation ( source)
- sprintf: documentation ( source)
<?php
$image = './image/testing.jpg';
$url = 'http://testing.com/randomdir';
$image_parts = parse_url($image);
$url_parts = parse_url($url);
// check to see if the image has a path of its own
if (dirname($image_parts['path']) == '.') {
$image_path = dirname($url_parts['path']) . DS . $image_parts['path'];
} else {
$image_path = $image_parts['path'];
}
if (empty($image_parts['host'])) {
$image_location = sprintf('%s://%s/%s/%s', $url_parts['scheme'], $url_parts['host'], dirname($url_parts['path']), $image_path);
} else {
$image_location = $image;
}
var_dump($image_location);