Jump to content

GD libray image save problem in IE


ansharma

Recommended Posts

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

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" );

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.

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.

 

 

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

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.

 

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.