Hello all
How can I get the file type from a string like this one
http://Awebsite.com/image.php?size=large&&imgcode=TMOV3
the plan is to call it somthing and save the image localy can this be done ?
Thanks All in advance
Hello all
How can I get the file type from a string like this one
http://Awebsite.com/image.php?size=large&&imgcode=TMOV3
the plan is to call it somthing and save the image localy can this be done ?
Thanks All in advance
You can try and use [man]getimagesize[/man] which returns image type as well.
Cheers m8
Looks like fun can't seem to get the extension from a url like the one above though.
my php isn't great
This: http://Awebsite.com/image.php?size=large&&imgcode=TMOV3
doesn't give you a filetype
A header does, or a file does. A link doesn't
Have tried this
$filename = "http://Awebsite.com/image.php?size=large&&img=TMOV3";
$size = getimagesize($filename);
$fp = fopen($filename,"rb");
if ($size && $fp) {
echo header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
I can see the ext in there but I get tons of gobaldy gooke in there with it is there a way to just grab the ext ?
can this not be done with a url like the above then ?
Have you seen the manual page for getimagesize?
Try something like:
$filename = "http://Awebsite.com/image.php?size=large&&img=TMOV3";
$size = getimagesize($filename);
if ($size) {
switch ($size[2]) {
case 1:
$ext=".gif";
break;
case 2:
$ext=".jpg";
break;
//add cases as in getimagesize manual
}//end of switch
} else {
// error
}
yep I had a look m8 but its not as well explained as you put it
cheers m8ty
Ok no laughing
This is what I have come up with (doesn't work of course)
<?php
$img = $_GET['img'];
$size = $_GET['size'];
$filename1 = "http://awebsite.com/image.php?size=$size&img=$img";
$size1 = getimagesize($filename1);
if ($size1) {
switch ($size1[2]) {
case 1:
$myext=".gif";
break;
case 2:
$myext=".jpg";
break;
case 3:
$myext =".png";
break;
case 4:
$myext =".swf";
break;
case 5:
$myext =".psd";
break;
case 6:
$myext =".bmp";
break;
//add cases as in getimagesize manual
}//end of switch
} else {
// error
}
if($size == "small") {
$filename = 'images/thumb_$img$myext';
}elseif($size == "large"){
$filename = 'images/$img$myext';
}
if (file_exists($filename)) {
// We have the image localy use it <--[
// Dont need to do anything here
$filen = $filename;
echo "it exists !";
} else {
echo "it does not size = $size and img = $img ext = $myext";
// We Dont have the Image Go Get it ]-->
if($size == "small") {
$filenname = 'http://awebsite.com/image.php?size=small&img=$img';
$src = fopen($filenname,"r");
if ($src)
{
$dst = fopen("images/thumb_$img$myext","w");
while(!feof($src))
{
fwrite($dst,fread($src,1024));
}
fclose($src);
fclose($dst);
$filen = "images/thumb_$img$myext";
}
}elseif($size == "large"){
$filenname = 'http://awebsite.com/image.php?size=large&img=$img';
$src = fopen($filenname,"r");
if ($src)
{
$dst = fopen("images/$img$myext","w");
while(!feof($src))
{
fwrite($dst,fread($src,1024));
}
fclose($src);
fclose($dst);
$filen = "images/$img$myext";
}
}
}
$size2 = getimagesize($filen);
$fp=fopen($filen, "rb");
if ($size2 && $fp) {
header("Content-type: {$size2['mime']}");
fpassthru($fp);
exit;
} else {
// error
echo "<p>error and filename = $filen</p>";
}
?>
Is there any error there?
What happens if you enter manually http://awebsite.com/image.php?size=xxxx&img=some_image into your browser? Does it return a picture?
All fixed
it was $size2 causing the problem it was empty