When download a file and rename the file in "Save File" dialog, the saved file will lose it's extension

245 views
Skip to first unread message

Kok Hwa LAU

unread,
Apr 28, 2015, 12:45:17 AM4/28/15
to phpde...@googlegroups.com
Good day,

I have tried to search for a while and the closest I can find is https://code.google.com/p/phpdesktop/issues/detail?id=65#makechanges where the last comment mentioned about this issue.

In my web app, when the user clicks on a button, I used the example code in http://php.net/manual/en/function.readfile.php to send a .xlsx file to the user for download. PHPDesktop will then open a "Save File" dialog for the user to choose where to save the file. If the user doesn't change the default file name, the file is successfully saved with the file extension (.xlsx) intact. However, if the user decides to change the file name in the "Save File" dialog, the saved file will lose it's file extension, causing an unknown file type when the user tries to open it.

Appreciate if you have any advice. Thanks.

Czarek Tomczak

unread,
Apr 28, 2015, 3:20:22 AM4/28/15
to phpde...@googlegroups.com
What PHP Desktop version? Does the problem reproduce for extension other than xlsx? How does the same script behave in Google Chrome? (run in Chrome by choosing "Open in external browser" from mouse context menu).

--
You received this message because you are subscribed to the Google Groups "PHP Desktop" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpdesktop+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phpdesktop.
To view this discussion on the web visit https://groups.google.com/d/msgid/phpdesktop/92f8cfd7-371c-4273-aa80-18ffe4f706a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kok Hwa LAU

unread,
Apr 28, 2015, 1:21:37 PM4/28/15
to phpde...@googlegroups.com
The version is "PHP Desktop Chrome 31.8 with PHP 5.4.33".
The problem reproduce for extension other than xlsx as well, I have tried .rtf and .doc

Below is my setup to replicate this problem:
  1. Create a view.php file in the webroot
  2. Copy a .xlsx file to the webroot, named abc.xlsx
  3. Edit the view.php to include an <a href="abc.xlsx">Download</a>
  4. Open PHPDesktop and view the view.php page
  5. Clicks on the Download link
  6. A "Save File" dialog will appear to choose the location to save the file, with default file name set to abc.xlsx
  7. Choose any location but change the file name to xyz (note without the .xlsx extension). I expect this should be fine as the "Save as type" below it is set to "Microsoft Excel..."
  8. Check the saved file and you will see that the file is without the .xlsx extension (thus unrecognized file type by the OS)
When I right click the Download link and "Open in external browser", it will open my browser and load the view.php page (but not download the .xlsx file).

Note that in step #7 above, if I rename the file to xyz.xlsx, then the file is correctly saved. Initially I suspect this is an acceptable behaviour. But when I open an Excel file using Microsoft Excel, and then click the "Save As..." to trigger the similar dialog, this dialog will correctly save the file even I name the file without the extension.

Kok Hwa LAU

unread,
Apr 30, 2015, 7:14:58 AM4/30/15
to phpde...@googlegroups.com
Hi Czarek,

Any idea how to fix that ? Do let me know if you need more info.

Thanks.

Kok Hwa LAU

unread,
May 3, 2015, 9:39:51 AM5/3/15
to phpde...@googlegroups.com
Seems like it's a CEF issue. I found the following:
http://www.bytebucket.org/chromiumembedded/cef/pull-request/11/windows-save-dialog-loose-file-extension/activity#

How can we use this version of CEF in our PHPDesktop ?

Czarek Tomczak

unread,
May 3, 2015, 12:25:29 PM5/3/15
to phpde...@googlegroups.com
When CEF accepts this pull request and phpdesktop updates to latest CEF it will be available in phpdesktop. Otherwise you would to apply the patch yourself and have to build CEF from sources which is a long process (at least a few hours up to a day). When it's done replace libcef.dll in phpdesktop.

Kok Hwa LAU

unread,
May 3, 2015, 1:12:43 PM5/3/15
to phpde...@googlegroups.com
I noticed that in phpdesktop download page, it is mentioned that the CEF used in PHPDesktop is branch 1650 rev. 1562

If I were to apply the patch myself, should I apply it to branch 1650 (and use the latest rev. ?) as well ? Is there any catch that I should be aware of when using different branch (or even rev.) of CEF ?

Once they accepted the pull request, we can actually get the nightly build from here:
https://cefbuilds.com/

Czarek Tomczak

unread,
May 3, 2015, 3:17:09 PM5/3/15
to phpde...@googlegroups.com
Branches 1650 and 2171 (rc) are available for phpdesktop. When using different branch/revision there might be a need to modify some code in case CEF API changed.

Branch 2171 has a double scroll speed bug unfortunately and this still wasn't fixed in upstream CEF. However a temporary fix I have created for cefclient (Issue 146 in phpdesktop).

Czarek Tomczak

unread,
May 3, 2015, 3:18:15 PM5/3/15
to phpde...@googlegroups.com
When using a different branch or revision then you need to rebuild phpdesktop binaries as well, see the BuildOnWindows wiki page.
Reply all
Reply to author
Forward
0 new messages