简体   繁体   中英

imagepng - creating in /public folder

How can I specify filepath to imagepng function? It always seems to create the file in "/public" folder when used in an MVC Zend Framework and even when an explicit filepath is supplied. Is it because of the rewrite rules I have? My .htaccess rewrite rules are as under:

FileETag none
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 years"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType application/x-unknown-content-type "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
</IfModule>

ExpiresActive On
ExpiresDefault A604800
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType text/html A300
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
ExpiresActive Off
</FilesMatch>


# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE
</Files>

RewriteEngine   on
# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost context
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

EDIT : Upon Closer examination it is your rewrite rules... Why are you using %{DOCUMENT_ROOT} ? You shouldnt need to mention it in your rewrite stack. That should be mapped directly in you vhost config. If you had to do that to get Zend to work something is either wrong in your app config or in your vhost. If youre hosting out of a sub dir of the docroot set the baseurl on the front controller.


What is the path youre trying to write to? You should use the full filesystem path to where you want the image written for example:

imagepng($image, APPLICATION_PATH.'/public/images/generated_image.png');

You should probably use other dynamic tools to build that path in case you ever change the actual directory for public but that was jsut a simple example :-)

If you use a relative path the path will always be relative to public because thats the dir index.php is in and it processes everything. The URL in the browser doesnt nessecarily reflect the path youre operating out of because of the standard rewrite rules/routing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM