Download GD image as attachment php
The user posts image data in a hidden field. I send the form to a blank page. The actual image is created server-side with the GD library and then the user can download it. 开发者_StackOverflowSo far so good, but Firefox doesn't download the image, it just displays it inline. I use this code:
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename="'.($_POST['savename']?$_POST['savename']:'yourpainting').'.'.$ext.'"');
imagejpeg($imagecreatedbygdlib)
If I use 'application/octet-stream' or 'application/force-download' Firefox just downloads the php page.
You may need all of the following headers
header("Content-Transfer-Encoding: binary");
header('Content-Description: File Transfer');
header('Content-Type: ' . $file_type);
header('Content-Length: ' . $file_size);
header('Content-Disposition: attachment; filename=' . $file_name);
To get the file_size, you will either need to save the file temporarily, or buffer the output.
精彩评论