we would be fascinated by using Google to upload photos while mean time we could grab the image by using JQuery and with some inbuilt functions in PHP.I have given a simple script to load the image from the given url and handled some Error occurings with the help of inbuilt functions.Any way You must need minimum PHP version to test this sample because the built in function i have used must have 5.3.2 version minimum as per Docs of PHP.
have a look at my code at codepen widget!
![]() |
A final capture from my localhost to grab image from url! |
php code:
This php code uses get parameter url and undergoes many test to check errors and atlast prints the url which is parsed with JQuery and displayed on clients page.
<?php
if($_GET['url']) {
$shiva=$_GET['url'];
if($info = new SplFileInfo($shiva)) {
if($s=$info->getExtension()) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
if(in_array($s, $allowedExts)) {
$size=getimagesize($shiva);
if($size && $size!=0 ) {
$img = $_GET['url'];
echo $img;
} else{echo "size error";}
} else{echo "existence array error";}
}else{echo "extension error";}
}else{echo "file error";}
}
else{echo "error";}
?>
Since i'm currently using free hosting and it is not above 5.3.2 version :D sorry i couldn't provide however i tried in my Localhost !if u get any error just mail me or comment below.share is care.
nice one @shiva
ReplyDelete