Posted By

flatearthcomms on 02/13/15


form php web fileupload

Versions (?)

translate non alphanumeric characters from file name into underscores

 / Published in: PHP


Translate non alphanumeric characters into an underscore. Doesn't create double underscores if there's two spaces in a row. Also turns name to lowercase. Use with trim to avoid spaces at front or end.

  1. $filename=trim($_FILES['pdf']['name']);
  2. $name = preg_replace('/[^a-z0-9.]+/', '_', strtolower($filename));

Report this snippet  

You need to login to post a comment.