Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:36:25+00:00 2026-05-25T09:36:25+00:00

Working with CakePHP and Java Web Start I’m generating the necessary .jnlp-file within a

  • 0

Working with CakePHP and Java Web Start I’m generating the necessary .jnlp-file within a controller in which among other things I set the filename as a header-field. That works fine as long I’m not trying to use special chars in the filenames. However, I’d like to enable every character that is possible on the main operating systems as a filename. So what I try to do is removing all the invalid characters by replacing them through empty strings. But there seems to be a problem with whitespaces which should be allowed in filenames.

That’s the code:

$panel_id = 1
$panelname = 'w h i t e s p a c e s';
$filename = sprintf('"Project_%d_%s.jnlp"', $panel_id, $panelname);
$invalid_chars = array('<', '>', '?', '"', ':', '|', '\\', '/', '*', '&');
$filename = str_replace($invalid_filenamechars, '', $filename);
$this->header('Content-Disposition: attachment; filename=' . $filename);

When I do that, the resulting filename in the header is ‘Project_1_w h i t e s p a c e’, while Windows 7 wants to save the file as ‘Project_1_w’. So it seems that my OS doesn’t accept unescaped whitespaces in filenames? I would be happy with that explanation if it wasn’t for the following: I left the lines 4 and 5, so that the code looks

$panel_id = 1
$panelname = 'w h i t e s p a c e s';
$filename = sprintf('"Project_%d_%s.jnlp"', $panel_id, $panelname);
$this->header('Content-Disposition: attachment; filename=' . $filename);

And now Windows is willing to save the file with all its whitespaces, still I cannot understand why. If I look at the filenames in the headers by using wireshark, both are the same. And if the sprintf-line is replaced by $filename = 'w h i t e s p a c e' or even $filename = $panelname it cuts the filename as in the first codesnippet. But I can replace the sprintf with the dottet-string-concat syntax and it works.

Can anyone tell me, what I’m overlooking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:36:25+00:00Added an answer on May 25, 2026 at 9:36 am

    The difference is the double quotes. With the first code you’ll end up with:

    Content-Disposition: attachment; filename=Project_1_w h i t e s p a c e s.jnlp
    

    with the second code you’ll end up with:

    Content-Disposition: attachment; filename="Project_1_w h i t e s p a c e s.jnlp"
    

    What you probably want is something like:

    $panel_id = 1;
    $panelname = 'w h i t e s p a c e s';
    $filename = sprintf('"Project_%d_%s.jnlp"', $panel_id, $panelname);
    $invalid_chars = array('<', '>', '?', '"', ':', '|', '\\', '/', '*', '&');
    $filename = str_replace($invalid_filenamechars, '', $filename);
    $this->header('Content-Disposition: attachment; filename="'.$filename.'"');
    

    This strips any double quotes within $filename, but then makes sure that $filename is always surrounded by double quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say i have: http://some-domain/application/controller/action/parameter This is somehow working in cakePHP. Now I want
I have uploaded a working Cakephp web application to Mosso Cloud Sites hosting. The
I have a local cakephp 1.2 app which was working fine last night. Currently
So i'm working with CakePHP v1.2.5. On my current project, I decided to start
I am currently working on configuring my CakePHP (1.3) based web app to run
setFlash stopped working in my CakePHP 1.3 app. The controller and view code is
I am a RoR developer, but I am presently working with CakePHP for a
I'm working on a CakePHP project and am currently building the user authentication part
I've just started working on an existing CakePHP project. I will be developing a
I am working on a CMS using CakePHP and I want to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.