PHP: How to sanitize uploaded filenames?

后端 未结 6 1945
生来不讨喜
生来不讨喜 2021-01-02 11:32

I have a PHP application.

I allow users to upload files to my web application.

Question: What\'s the best way for me to sanitize the file n

6条回答
  •  灰色年华
    2021-01-02 12:08

    If you're not against losing the actual filenames, what I usually do is create a hash of the filename and set the filename to that, if whatever you're developing has loads of pictures being uploaded it helps avoid conflicts where two filenames are named alike and overwrites occur.

    hash('md5', $_FILES["filename"]["tmp_name"]);
    

提交回复
热议问题