Jump to content

Characters to keep out of text files


railgun

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.