Log in

View Full Version : PHP and Javascript



hemi519
12-25-2010, 09:33 AM
Hi All,

can anyone help me,.The below is my code


$size = getimagesize("uploads/image.jpeg");
$message = "$size[mime]";

if ($message!=image/jpeg)
{
echo"this image format is not supported"; (here i need it to be displayed as javascript alert, is it possible)
}

and the other thing is, when i used getimagesize()

$size=getimagesize("uploads/image.jpeg");
print_r($size)

Array ( [0] => 2560 [1] => 1600 [2] => 2 [3] => width="2560" height="1600" [bits] => 8 [channels] => 3 [mime] => image/jpeg )

Actually the image is around 60 kb. but it is not showing any image size in the above.

jscheuer1
12-25-2010, 03:43 PM
The code you show can probably be made as a javascript alert like so:


$size = getimagesize("uploads/image.jpeg");
$message = "$size[mime]";

if ($message!=image/jpeg)
{
?><script type="text/javascript">
alert("this image format is not supported");
</script><noscript>
this image format is not supported
</noscript>
<?php
}

I say probably because I can't see everything else or the served source code. But if it was echoing, it should now alert. Except if javascript is disabled, in which case it will still write the information to the page.



The PHP function getimagesize() is for dimensions and a few other things, not bytes. If you want bytes, use the PHP filesize() function.

hemi519
12-25-2010, 04:48 PM
thnku