- substr: documentation ( source)
- file_get_contents: documentation ( source)
- var_dump: documentation ( source)
- rawurlencode: documentation ( source)
- urlencode: documentation ( source)
<?php
$var = 'http://sandbox.case-store.ch/images/27-12-2014 13-50-47.png';
$var2 = 'sandbox.case-store.ch/images/27-12-2014 13-50-47.png';
function getImageContentRaw($url) {
try {
echo 'Stage0';
return file_get_contents(rawurlencode($url));
} catch (PHPException $ex) {
// Ignore error and try http and https prefix
}
if (substr($url, 0, 7) === 'http://' || substr($url, 0, 7) === 'https://') {
echo 'Stage9';
return false;
}
try {
echo 'Stage1';
return file_get_contents(urlencode('https://'.$url));
} catch (PHPException $ex) {
// Ignore error
}
try {
echo 'Stage2';
return file_get_contents(urlencode('http://' . $url));
} catch (PHPException $ex) {
// Ignore error
}
echo 'Stage8';
return false;
}
var_dump(getImageContentRaw($var));
var_dump(getImageContentRaw($var2));