Reputation: 43
Hey i have the following script, basicaly a flash file sends it some data and it creates a image and then opens a save as dialog box for the user so that they can save the image to there system.Here the problem comes in, how would i go about also saving the image to my server?
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$fname = $_POST['fname'];
$send = $_POST['send'];
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$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-Disposition: attachment; filename=test.jpg" );
header("Content-type: image/jpeg");
ImageJPEG( $image );
imagedestroy( $image );
?>
Help would be greatly appreciated!
Upvotes: 2
Views: 5544
Reputation: 12866
The slightly fancier way so save on duplicated effort would be something like,
/* start output buffering to save output */
ob_start();
/* output image as JPEG */
imagejpeg( $image );
/* save output as file */
ob_flush();
file_put_contents( $filename, ob_get_contents() );
Upvotes: -1
Reputation: 83622
imagejpeg( $image, $filename );
will save the image to $filename
. So essentially could do
imagejpeg( $image, $filename );
imagedestroy( $image );
readfile( $filename );
instead of just calling
imagejpeg( $image );
Upvotes: 4