danturn Posted August 20, 2009 Share Posted August 20, 2009 Hey guys, I'm new both here and to PHP so be kind ;p I'm rewriting an app i originally wrote in VB to be web based using php... its a remote control for cisco voip phones. I'm just starting out and have so far been able to write the PHP (with a bit of help with the image translation) to grab screenshots from the phone... my problem is when I click submit on my form (after entering the IP, UserID and PIN) it displays the screenshot and all of the form fields vanish. This is probably incredibly simple and i'm being stupid but how can i specify where the image goes and how to keep the other fields? Ideally I want to build more of an interface so it looks like a phone and have the screenshot appear in a picture box in a fixed location... my code is below: <?php if (isset($_POST['submit'])) { $ips = $_POST['IP']; $USERID = $_POST['USERID']; $PIN = $_POST['PIN']; $data = file_get_contents("http://".$USERID.":".$PIN."@".$ips."/CGI/Screenshot"); $filename = tempnam("/tmp/", "CPS"); file_put_contents($filename, $data); $im = imagecreatefrombmp($filename); unlink($filename); header("Content-Type: image/png"); imagepng($im); } function ImageCreateFrombmp($filename) { if(!$f1 =fopen($filename,"rb")) { return false; } $file = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14)); if($file['file_type'] != 19778) { return false; } $bmp = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel/Vcompression/Vsize_bitmap/Vhoriz_resolution/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40)); $bmp['colors'] = pow(2,$bmp['bits_per_pixel']); if($bmp['size_bitmap'] == 0) { $bmp['size_bitmap'] = $file['file_size'] - $file['bitmap_offset']; } $bmp['bytes_per_pixel'] = $bmp['bits_per_pixel']/8; $bmp['bytes_per_pixel2'] = ceil($bmp['bytes_per_pixel']); $bmp['decal'] = ($bmp['width']*$bmp['bytes_per_pixel']/4); $bmp['decal'] -= floor($bmp['width']*$bmp['bytes_per_pixel']/4); $bmp['decal'] = 4-(4*$bmp['decal']); if($bmp['decal'] == 4) { $bmp['decal'] = 0; } $palette = array(); if($bmp['colors'] < 16777216) { $palette = unpack('V'.$bmp['colors'], fread($f1,$bmp['colors']*4)); } $im = fread($f1,$bmp['size_bitmap']); $NULL = chr(0); $res = imagecreatetruecolor($bmp['width'],$bmp['height']); $P = 0; $Y = $bmp['height']-1; while ($Y >= 0) { $X=0; while ($X < $bmp['width']) { if($bmp['bits_per_pixel'] == 24) { $color = unpack("V",substr($im,$P,3).$NULL); } else if($bmp['bits_per_pixel'] == 16) { $color = unpack("n",substr($im,$P,2)); $color[1] = $palette[$color[1]+1]; } else if($bmp['bits_per_pixel'] == { $color = unpack("n",$NULL.substr($im,$P,1)); $color[1] = $palette[$color[1]+1]; } else if($bmp['bits_per_pixel'] == 4) { $color = unpack("n",$NULL.substr($im,floor($P),1)); if(($P*2)%2 == 0) { $color[1] = ($color[1] >> 4); } else { $color[1] = ($color[1] & 0x0F); } $color[1] = $palette[$color[1]+1]; } else if($bmp['bits_per_pixel'] == 1) { $color = unpack("n",$NULL.substr($im,floor($P),1)); if(($P*%8 == 0) { $color[1] = $color[1]>>7; } else if(($P*%8 == 1) { $color[1] = ($color[1] & 0x40)>>6; } else if(($P*%8 == 2) { $color[1] = ($color[1] & 0x20)>>5; } else if(($P*%8 == 3) { $color[1] = ($color[1] & 0x10)>>4; } else if(($P*%8 == 4) { $color[1] = ($color[1] & 0x8)>>3; } else if(($P*%8 == 5) { $color[1] = ($color[1] & 0x4)>>2; } else if(($P*%8 == 6) { $color[1] = ($color[1] & 0x2)>>1; } else if(($P*%8 == 7) { $color[1] = ($color[1] & 0x1); } $color[1] = $palette[$color[1]+1]; } else { return false; } imagesetpixel($res,$X,$Y,$color[1]); $X++; $P += $bmp['bytes_per_pixel']; } $Y--; $P+=$bmp['decal']; } fclose($f1); return $res; } ?> <form action="mung.php" method="POST"> <table> <tr> <td>IP:</td> <td><input type="text" name="IP"></td> </tr> <td>User ID:</td> <td><input type="text" name="USERID"></td> </tr> <td>Pin:</td> <td><input type="text" name="PIN"></td> </tr> <td><input type="submit" name="submit" value="submit"></td> </tr> <form> Basically... I'm not sure I need to use this massive function as the phone does return a bmp file when you query it.. someone else very kindly pointed the function out to me. Can anyone point me in the right direction to: send an http request to the phone and receive the bmp image response more simply than I am already doing and/or set the image response from the function (or an easier way) to appear in a picture box/fixed location. As I said, I'm a n00b. I know exactly what i need to do and how to do it in VB.net but am finding php challenging so far! Dan Quote Link to comment https://forums.phpfreaks.com/topic/171162-basic-php-forms-question/ Share on other sites More sharing options...
danturn Posted August 25, 2009 Author Share Posted August 25, 2009 Just to simplify this as i think i made it to confusing: I'm using the imagepng($im) command to display an image... but when i use that it puts the png as the whole page and the form disappears... I also tried doing this... imagepng($im,temp.png) then using img src="temp.png" to display the image on the form correctly but it didn't refresh the image correctly and it seemed quite an ugly way to do it. Is there any way to use imagepng($im) to put the png image created into my form? Dan Quote Link to comment https://forums.phpfreaks.com/topic/171162-basic-php-forms-question/#findComment-905670 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.