admin-ajax.php imgedit-preview header problem
-
Hi.
I can’n be sure that I’m in the right section of this forum. Actually I’m am here because I’m not sure about what’s happening… rs
Well, I use the “Post thumbnail Editor” in my website. After move my site to a IIS Server (I know, it sux, but my customer call for it), the page for select area for the thumbnail did not show the main image anymore.
After debug many .php files, I found that the source of this bug was a WordPress core instruction. In the wp-admin/includes/image-edit.php you can found these lines (beginning at line 239):
function wp_stream_image($image, $mime_type, $post_id) { $image = apply_filters('image_save_pre', $image, $post_id); switch ( $mime_type ) { case 'image/jpeg': header('Content-Type: image/jpeg'); return imagejpeg($image, null, 90); case 'image/png': header('Content-Type: image/png'); return imagepng($image); case 'image/gif': header('Content-Type: image/gif'); return imagegif($image); default: return false; } }
In my tests, I have used jpeg images and, I can’t say why, the header had no effect and the image was blank.
Searching for a solution, a have found this forum page and a instruction call my attention. And it solved the bug!
function wp_stream_image($image, $mime_type, $post_id) { $image = apply_filters('image_save_pre', $image, $post_id); while (@ob_end_clean()); switch ( $mime_type ) { case 'image/jpeg': header('Content-Type: image/jpeg'); return imagejpeg($image, null, 90); case 'image/png': header('Content-Type: image/png'); return imagepng($image); case 'image/gif': header('Content-Type: image/gif'); return imagegif($image); default: return false; } }
I found that this ob_end_clean function “discards the contents of the topmost output buffer and turns off this output buffering”. Ok, it works for me, but what I want to know is if is safe to call this function there. As I said, I’m at WordPress Core. Does anyone know a better solution?
Many thanks!
- The topic ‘admin-ajax.php imgedit-preview header problem’ is closed to new replies.