We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I'm hoping one of you Windows gurus will be able to suggest something. I have a form using eForm that allows the upload of files, with a link to the file provided in the email report. The problem is that on a Windows server the PHP move_uploaded_file function will end up with the filename in the charset of the Windows server. This is a big problem if the user uploads a file with special characters, such as a German umlaut. The link to the file is broken, since the utf8 filename taken from the form field is not the same as the filename with the Windows server character set. Nor can the file be downloaded from the MODx file manager.

    I would really hate to try to convert the site (it's in four languages) from utf8 to whatever charset the server is using, even if I could find out what that is.

    Does anyone have a recommendation of what to do? Perhaps rename the file after the move_uploaded_file function? Regular expression replacements of all special characters? Maybe a javascript to replace these in the form field before submission? I (and the client) would much prefer to keep the file name as they uploaded it.

    Asking the users not to upload files with such names, even having a warning message on the form, didn't work.

    [ed. note: sottwell last edited this post 12 years, 1 month ago.]
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
    • Ok, I solved the problem. Anywhere you need to use the filename (such as in an eForm report)
      $value = iconv("UTF-8", "Windows-1252//TRANSLIT", $value);

      will do the trick.

      This will mean you'll have to switch browsers and ftp clients to that charset to be able to see the filename correctly, but at least it makes it possible to use it for download links in an eForm report. You'll need an event function to convert the filename in the $files['filename'] array value; use eFormOnBeforeMailSent. [ed. note: sottwell last edited this post 12 years, 1 month ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org