使用zend框架将文件写入/ public

I am trying to create a dynamic sitemap for my site, which runs on Zend.

I want one of my controllers to be able to write to the /public directory, but I can't figure out how to get the file written to the right place.

My relevant directory structure is something like:

.application/

....modules/

.......my_module/

..........controllers/

.............SitemapController.php

.library/

.public/

Is this a simple way in Zend to point at the public/ directory without writing something ugly like "file://../../../public/" every time?

The Zend framework bootstrap defines a constant called APPLICATION_PATH following that guideline you can initialize another constant that points to the public path:

define('PUBLIC_PATH', APPLICATION_PATH . '/../public/');

This will then be available everywhere. Make sure that the webserver has write permissions to the folder you want to store files in.

You can use $_SERVER['DOCUMENT_ROOT'] but you shouldn't -- for security, the public dir shouldn't be writable by the process that runs the web server. There are a number of ways around this. You could write the file to some other stand-alone directory outside the document root and then symlink to it. Or maybe just create a route in your app config so that the file gets generated on the fly every time.