[mapserver-users] PHP $imgObj->saveImage(null) sends headers

Miloslav Kmeť miloslav.kmet at gmail.com
Mon Apr 5 15:00:56 EDT 2010


Hi I am sure, that I get an error with the latest code in this branch: 
https://svn.osgeo.org/mapserver/branches/branch-5-6/mapserver

My PHP version is 5.3.2.

Try this simple frameworkless php code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$map = ms_newMapObj('./test.map'); // select your usual mapfile
$img = $map->draw();

ob_start();
$img->saveImage(null);
$data = ob_get_clean();

header('Content-type: image/jpeg');
echo $data;
?>

The error is:
Warning: Cannot modify header information - headers already sent in 
/www/test/buffer/mapserver/ob-reproduce.php on line 11

I do not have a problem with collecting the data or using them. The problem is 
to send headers after $img->saveImage(null) call.

Because of the symfony's framework behaviour - controller creates the data and 
the response later send them with additional headers I cannot send the headers 
before $img->saveImage();

If you change your code and puts the header('Content-type: image/png'); before 
imagepng($image); you will see that error.

Thank you for giving a try.
 
On pondelok 05 Apríl 2010 19:37:02 you wrote:
> Oh sorry, your code is correct thought you used ob_end_clean and you
> are using ob_get_clean. But the snippet works for me with out any
> phpmapscript modification.
> 
> 2010/4/5 Pavel Iacovlev <iacovlev.pavel at gmail.com>:
> > 1) Your php code is not correct I think, ob_get_clean  just cleans the
> > output and does not return the captured content.
> > 2) Try with no framework, maybe it sends some headers before you run your
> > code.
> > 
> > This works for me in Zend Framework in MVC mode, should work for symfony
> > too. ob_start();
> > $image->saveimage('');
> > $image = imagecreatefromstring(ob_get_contents());
> > ob_end_clean();
> > imagepng($image);
> > 
> > 2010/4/5 Miloslav Kmeť <miloslav.kmet at gmail.com>:
> >> Hi. I am trying to use php_mapscript in MVC framework (symfony) and I
> >> want to catch the output of $imgObje->saveImage(null); for the later
> >> processing, eg: using the builtin cache mechanism instead of directly
> >> writing the file to the cache.
> >> 
> >> My code very simplified looks like:
> >> 
> >> ob_start();                            // start output buffering
> >> $imgObj->saveImage(null);  // print output to std
> >> $image = ob_get_clean();   // get the buffer and clen it
> >> 
> >> header('Content-type: image/jpeg'); // setting the header
> >> echo $image; // printing the image
> >> 
> >> At the header line I got an header already sended error, even no output
> >> will be brinted before.
> >> 
> >> I looked into php_mapscript.c and I found that in the saveImage function
> >> there is php_header(TSRMLS_C); As I do not know the PHP internals, i do
> >> not know what that call is doing, but when I removed it out, and
> >> recompiled the extension,
> >> 
> >> Now output buffering is working correctly.
> >> 
> >> What is the function doing? Should it be replaced in the main
> >> development?
> >> 
> >> Thanks
> >> --
> >> Miloslav Kmeť
> >> 
> >> _______________________________________________
> >> mapserver-users mailing list
> >> mapserver-users at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/mapserver-users
> > 
> > --
> > http://iap.md, The future is open

-- 
Miloslav Kmeť


More information about the mapserver-users mailing list