简体   繁体   中英

How to disallow special characters on file name like “()” upon uploading image?

I'm working on my program where the user will upload images to the document/folder. There is a modify image button on my page where the user can edit or add some information to the image.

This is the URL for uploads: SAMPLE/index.php/document

Then I uploaded the sample.jpg // it works on modify

Again, I uploaded new image. This time with spacial characters sample_(3)1.jpg // didn't work! The URI you submitted has disallowed characters.

This is the URL for modify: SAMPLE/index.php/document/modify_document/sample_(3)1.jpg

I had tried to include validation on URI and refer to this disallowed characters , but the problem is some of my web pages got affected. (I have lots of pages on my web site)

What I think could be the best solution for this is to notify the user that uploading files with special characters is not allowed. I don't know how to do this in CodeIgniter. If you have any idea please do not hesitate to post your answer. Thanks!

Actually, you might not need to do that. Consider that, all your user file upload will be storing in one single directory on your server, if two user uploaded a file with the same name, or a user upload a file with same file name, you are going have problem referring to them.

So usually what I do is to store the file (on the file system) with it's temp name, like, $_FILES ["yourfile"] ["tmp_name"] , then store this file name for edit in the data base together with another fields which store the "display name" to show to the user, or to be the name of the file when user want to download the file back.

Something like

table user_uploaded_pic {id,filepath,displayname}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM