How can I replace white space in filename of uploaded file

后端 未结 3 1269
名媛妹妹
名媛妹妹 2021-01-18 15:41

I\'m making a SWF uploader and have my HTML form done.

It works totally fine until I upload a SWF file with spaces in the name.

How can I replace whitespace

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 16:04

    I usually approach it from the other side and only allow characters from a white-list; I replace everything except these characters:

    $file = preg_replace("/[^-_a-z0-9]+/i", "_", $file);
    

提交回复
热议问题