railgun Posted January 1, 2010 Share Posted January 1, 2010 I have a site that is using a form to upload potentially large text files. What are the common characters and symbols to keep out of these files so they don't get into the db. And would you use regex to police it? Thanks in advance for your expertise. Quote Link to comment https://forums.phpfreaks.com/topic/186834-characters-to-keep-out-of-text-files/ Share on other sites More sharing options...
premiso Posted January 1, 2010 Share Posted January 1, 2010 You can generally have any file name in the db, just make sure to mysql_real_escape_data for them. If you want them to be SEO friendly then you tend to want to replace anything but alphanumeric and _ -s. If you do not care about that you should not have a problem. Just make sure when the file is uploaded to rename it to a hash of the name so it does not create invalid files (such as uploading a file with certain charaters can make that file undeleteable). Moving to the regex forum so someone can provide a regex solution to replace all non alphanumeric if you so desire that. Quote Link to comment https://forums.phpfreaks.com/topic/186834-characters-to-keep-out-of-text-files/#findComment-986663 Share on other sites More sharing options...
Brandon_R Posted January 1, 2010 Share Posted January 1, 2010 Adding onto the SEO suggestion the above posted suggested, the regex i would use for a nice SEO friendly name will be '#^[A-Z0-9._-]#si' [/cODE] Basically that allows any alphanumeric character, an underscore, a dash or a period. You might want to add or remove constraints as you wish. Windows doesn't allow slashes, arrows, colon, asterick, question mark bar or quotation marks in file names so you might want to prevent files to be named this incase a user downloads the file and gets an error on his/her windows pc. Quote Link to comment https://forums.phpfreaks.com/topic/186834-characters-to-keep-out-of-text-files/#findComment-986897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.