ansharma Posted February 18, 2011 Share Posted February 18, 2011 Hi all, i need little help in saving and download gif image created by using GD library. code works fine in mozilla and crome but in IE a new new page where the image is created,saved as well as dowloaded remains open and shows this"Action canceled". but the image is stored and downloaded on my system. i just want to close this page automatically when download is complete <?php ob_start(); ini_set("memory_limit","180M"); $data = explode(",", $_POST['img']); $width = $_POST['wp']; $height = $_POST['ht']; $image=imagecreatetruecolor( $width ,$height ); $background = imagecolorallocate( $image ,0 , 0 , 0 ); //Copy pixels $i = 0; for($x=0; $x<=$width; $x++){ for($y=0; $y<=$height; $y++){ $int = hexdec($data[$i++]); $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); imagesetpixel ( $image , $x , $y , $color ); } } //Output image and clean header( "Content-type: image/gif" ); $name = rand(0,9999); $n = $name; $name = "img/".$name.".gif"; ImageGIF($image,$name,100); imagedestroy($image); $path = "http://localhost/madeup/img/"; $fullPath = $path.$n.'.gif'; if ($fd = fopen ($fullPath, "r")) { header( "Content-type: image/gif" ); header("Content-Disposition: attachment; filename=".$n); header("Cache-control: private"); while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose ($fd); ob_end_flush(); exit; ?> Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/ Share on other sites More sharing options...
BlueSkyIS Posted February 18, 2011 Share Posted February 18, 2011 it looks like you're saving the image to disk first, in which case you DO NOT want to send header() of any kind before saving the file. it looks like you want to send the image to the browser after the file is saved. Then it is necessary to send the headers like you've done. long store short: remove the first header( "Content-type: image/gif" ); Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176286 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 thanks for your suggestion it really optimized my code, but my problem is that when i use INTERNET EXPLORER then all functions are completed successfully but a new browser remain opened(in url bar the address of this page is displayed : http://localhost/madeup/show.php ) and display a message "Action cancelled", which looks odd. but when i use any other web browser then only an a promt displayed asking for opening the downloaded file or save file at any location. Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176302 Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 Do you use target="_blank" when linking to the script above? I remember having a problem like this and I think I solved it opening the link in the same page. If IE sees that the action has been canceled then it shouldn't reload the page. Try it out and let me know. Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176317 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 no actually i am using a flash application in which when you click save button the flash sends pixel values, height, width to a file called show.php and all is done in the same file. it working fine but problem with IE is, show.php remains open but if i use mozilla then show.php opend for while then closed automatically and a prompt for download location is left behind. i just want to close that show.php in IE only Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176325 Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 I just looked into it, and it seems IE is caching the page, and I found a fix. Try to insert the following lines before the first header(): header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); Let me know how it works out. Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176335 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 thanks but the problem remains same i am attaching the screenshots. It may help to understand my problem [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176346 Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 I assume you use actionscript to open that link? What function do you use: getURL() or navigateToURL() ? Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176347 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 i am using this import flash.display.BitmapData; snap = new BitmapData(masker._width, masker._height); snap.draw(pan); var pixels:Array = new Array(); var w:Number = snap.width; var h:Number = snap.height; for (var a = 0; a<=w; a++) { for (var b = 0; b<=h; b++) { var tmp = snap.getPixel(a, b).toString(16); pixels.push(tmp); } } var output:LoadVars = new LoadVars(); output.img = pixels.toString(); output.ht = h; output.wp = w; output.send("show.php", "output", "POST"); Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176348 Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 Look closely to: output.send! The send function's second parameter is: target. "Output" is not a valid target, target has to be one of the following: _blank, _self, _parent and _top. Replace "output" with "_self" and it should work. Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176354 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 thanks eutu9 let me try.... Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176356 Share on other sites More sharing options...
ansharma Posted February 18, 2011 Author Share Posted February 18, 2011 Thanks A lot eutu9 it works! Link to comment https://forums.phpfreaks.com/topic/228108-gd-libray-image-save-problem-in-ie/#findComment-1176359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.