Welcome, Guest
Username Password: Remember me

Validate Media filenames (RE special characters)
(1 viewing) (1) Guest

TOPIC: Validate Media filenames (RE special characters)

Validate Media filenames (RE special characters) 14 Jul 2009 14:40 #993

At our church, we love your component and wanted to thank you for it.

However, one issues keeps cropping up: inexperienced users who select file names that have special characters and spaces in them, which, when uploaded to the main server cause issues with the Bible Studies Podcast generation.

Is there any way to:

1. Perform a check upon file name selection for a new media file to be uploaded to see if the name has any spaces or special characters (other than dashes or underscores of course).
2. If any are detected, perform one of two different actions (depending upon a component configuration setting):
a. Warn the user about no special characters or spaces being allowed, and prevent the upload by taking them back to the media file page.
b. Replace all spaces and special characters with underscores automatically for the file that is saved on the server.

Please let me know if this enhancement request is possible.

Thanks!

Best Regards,
Eric

Re:Validate Media filenames (RE special characters) 14 Jul 2009 14:56 #994

  • Tom
  • OFFLINE
  • Administrator
  • Posts: 860
We've put it in as a feature request.
"You shall know the truth and the truth shall set you free." JC

Re:Validate Media filenames (RE special characters) 16 Jul 2009 22:02 #998

  • Tom
  • OFFLINE
  • Administrator
  • Posts: 860
What other characters besides spaces do you think should be changed into underscores to make the filename web safe? I have coded the model in version 6.1 to remove spaces and replace them with _.

Tom
"You shall know the truth and the truth shall set you free." JC

Re:Validate Media filenames (RE special characters 17 Jul 2009 00:30 #999

Hi Tom,

Anything other than dashes or underscores should be replaced.  For instance, the phrase "07/12/2009:  Pastor Nate: Saving & Freedom" might be replaced as the following: "07_12_2009___Pastor_Nate__Saving_and_Freedom".

The reason being that the non-encoded standard for URLs for filenames only allows for dashes "-" and underscores "_".  Everything else needs to be encoded in order to work, but that can be very problematic.  For this purpose, it's best to go with the lowest common denominator.  The only thing that should be different than underscores should be the ampersand "&", which should be replaced with the word "and".

Is this doable?

Thanks!

-Eric

Re:Validate Media filenames (RE special characters 17 Jul 2009 08:11 #1000

  • Tom
  • OFFLINE
  • Administrator
  • Posts: 860
I added these lines to the model that save the file name:

$badchars = array(' ', '`', '@', '^', '!', '#', '$', '%', '*', '(', ')', '[', ']', '{', '}', '~', '?', '/', '>', '<', ',', '|', '\\', ';', ':');
$data['filename'] = str_replace($badchars, '_', $data['filename']);
$data['filename'] = str_replace('&', '_and_', $data['filename']);

Hopefully this catches all the characters and spaces that could cause problems and changes them into underscores.
"You shall know the truth and the truth shall set you free." JC

Re:Validate Media filenames (RE special characters 17 Jul 2009 08:51 #1001

This is perfect! Thank you very much!

Will this version with this updated code be out soon?
Time to create page: 0.57 seconds