Check this code:

PHP Code: 
<?php
function addnvalidateurls($url){
// Modified By: Soft2050
if (!preg_match("@^[hf]tt?ps?://@"$url)) {
        
$url "http://" $url;
}
$pattern '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
return 
preg_match($pattern$url);


$result addnvalidateurls('http://www.google.com');
echo 
'<script language="javascript">';
if (
$result == 1)
echo 
"alert('Yes! The given url is validated')";
else {
echo 
"alert('No! the given url seems to be not working')";
}
echo 
'</script>';
?>
You can add this code before remote uploading the url

If Url is not valid, then you can break the function to end it