Forums / General / Download file name, always index.php.pdf

Download file name, always index.php.pdf

Author Message

Gabriele Perego

Tuesday 26 April 2011 3:02:23 am

Hi guys!

I'm using the same code on every eZ installation and it works fine. The code produce an address like this:

http://sitename.it/subfolder/index.php?/content/download/587/3094/file/file_name.pdf

The download works but the downloaded file name is index.php.pdf
As you note, the site is running in GCI modo on a shared server (no .htaccess, eZ version 4.4).

Any suggestions? the client wants the right file name :)

Marko Žmak

Tuesday 26 April 2011 4:41:03 am

It seems like the question mark ("?") is causing your problem - everything after it is considered a query string by the browser and it's not used for filename.

Could you paste the code you use to generate the download link?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Gabriele Perego

Tuesday 26 April 2011 5:12:16 am

Hi Marko, thanks for the reply, this is the code:

<a href={concat("content/download/",
$dati_soc.contentobject_id,
"/",
$dati_soc.data_map.pdf.id,
"/file/",
$dati_soc.data_map.pdf.content.original_filename)|ezurl()}>
{$dati_soc.data_map.link_2.content}
</a>

Marko Žmak

Tuesday 26 April 2011 6:49:09 am

When you enter manually your link without the question mark, like this:

  • http://sitename.it/subfolder/index.php/content/download/587/3094/file/file_name.pdf

does it work?

There is a solution mentioned about this problem:

  • http://share.ez.no/forums/install-configuration/url-s-in-website-not-working-properly

but I think it won't help you if the test above fails.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Gabriele Perego

Tuesday 26 April 2011 8:23:05 am

Yes, it fails :(

Marko Žmak

Tuesday 26 April 2011 8:49:59 am

OK, I think that if you don't make it work without the questionmark there's little chance to solve your problem (someone correct me if I'm wrong).

There is a chance that it will work in some browsers, since when downloading via content/download eZP does write the correct filename in the "Content-disposition" header of the response. But some browsers may use "filename" from the URL instead (then you have a problem not related to eZP but to the CGI mode).

Some ideas to try:

  • use the apache rewrite rules to make your pages work even without the questionmark (so that the test I suggested passes)
  • see in what browsers you get the right filename and in which you don't
  • check if the response has the proper filename in the "Content-disposition" header

I suggest to start with the first point and if that succeeds then you only have to make eZP not to generate your links with the questionmark.

Also, there was recently a post about running eZP in CGI mode:

  • http://share.ez.no/forums/install-configuration/work-arrounds-for-using-ez-publish-with-php-cgi

I believe this could help you with setting the appropriate rewrite rules.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Gabriele Perego

Wednesday 27 April 2011 5:35:10 am

Thanks Marko, I'll give it a try!

Gabriele Perego

Friday 29 April 2011 2:54:24 am

Hi Marko,

  • I try to use the .htaccess rules suggested in the thread, but it doesn't work
  • I try Safari, Chrome, Firefox, Opera on Mac but the fila name is always "index.php" (in Opera is index.pdf in Safari is index.php.pdf)
  • I check the "Content-disposition" header in httpfox and it was "attachment"

In conclusion, the problem is still there :(

Gabriele

Marko Žmak

Friday 29 April 2011 6:46:41 am

Ok, just to make it straight... The .htaccess rules won't fix your problem, they should only be used to enable your server to handle URLs without questionmark correctly. So after the changiong the rewrite rules, does the test link I suggested work?

As for the "Content-disposition" what's the exact value of this header? Is it only "attachment" or it has also a filename? Could you paste the entire header here?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Gabriele Perego

Monday 02 May 2011 12:53:45 am

Hi Marko,

after changing the .htaccess the link doesn't work, only the home page works... This is the content:

"

<FilesMatch "(^index\.php|favicon\.ico|index_treemenu\.php|\.(gif|jpe?g?|png|css|js|swf|html?)|var(.+)storage.pdf(.+)\.pdf|(\/z.+\.php))$">
order allow,deny
allow from all
</FilesMatch>

RewriteEngine On
RewriteRule content/treemenu/? index_treemenu.php
RewriteRule ^index_treemenu\.php - [L]
RewriteRule ^favicon\.ico - [L]
RewriteRule !(\.(gif|jpe?g?|png|css|js|swf|html?)|var(.+)storage.pdf(.+)\.pdf|(\/z.+\.php))$ index.php?/
DirectoryIndex index.php

"

This is the entire header:

(Status-Line) HTTP/1.1 200 OK
Date<span> </span>Fri, 29 Apr 2011 14:31:50 GMT
Server<span> </span>Apache/2.2.14 (Unix)
Served-by<span> </span>www.bitossiceramiche.it
Content-Language<span> </span>it,it-it
Expires<span> </span>Fri, 29 Apr 2011 14:41:51 GMT
X-Powered-By<span> </span>eZ PublishContent-Disposition<span> </span>attachment
Content-Transfer-Encoding<span> </span>binary
Accept-Ranges<span> </span>bytes
Last-Modified<span> </span>Fri, 22 Apr 2011 16:15:54 GMT
Content-Length<span> </span>82402
Content-Type<span> </span>application/pdf
Keep-Alive<span> </span>timeout=2, max=90
Connection<span> </span>Keep-Alive

Marko Žmak

Monday 02 May 2011 1:27:02 am

I think that rewrite rule don't work for your link because you have ".pdf" in this line:

RewriteRule !(\.(gif|jpe?g?|png|css|js|swf|html?)|var(.+)storage.pdf(.+)\.pdf|(\/z.+\.php))$ index.php?/

Try removing the "\.pdf" part.

Also try using this rewrite rules and then open your link without index.php, like this:

  • http://sitename.it/subfolder/content/download/587/3094/file/file_name.pdf

and then see what happens.

As for the "Content-disposition" part, when I checked on one of my eZP installation there was a filename in this header, but in your example it isn't. Strange...

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Gabriele Perego

Monday 02 May 2011 2:58:01 am

Ok, I change the .htaccess with this results:

  • http://www.sitename.it/subfolder/index.php/content/download/587/3094/file/file_name.pdf -> Homepage without CSS
  • http://www.sitename.it/subfolder/content/download/587/3094/file/file_name.pdf -> 404

I also check an other eZP installation and "Content-disposition" header has this value:

Content-Disposition<span> </span>attachment; filename="file_name.pdf"

Marko Žmak

Monday 02 May 2011 4:25:52 am

Ok, let's try to deal with this Content-Disposition part. Maybe it's a bug in eZ and maybe this can be the solution. So:

  • what's the eZP version on this other installation where you do have filename in Content-Disposition?
  • is this other installation also running in CGI mode? (is it on the same server?)
  • could you try to produce in this other instllation the same link as in your post? (and then see how it behaves)

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth