You mean like this? This would work as a good file name to be on the server and link to?

$filename = urlencode($_FILES['myfile']['name']);
move_uploaded_file($_FILES['myfile']['tmp_name'], $filename);

Think that would do the trick?


Eddie Drapkin wrote:
Why not just urlencode() the filename? (and suggest people use a URL shortening service and/or provide one)

On Wed, Jun 3, 2009 at 12:31 PM, Richard Heyes < <>> wrote:


     > I have a file uploader module that allows users to upload
    documents and of
     > course people are using all kinds of file names that are not web
     > I guess the best solution is to replace any non alphanumeric with
    maybe '_'
     > the underscore? How does that sound?
     > Unfortunately, after 20+ years of coding I cannot get my brain around
     > regular expressions to any decent level of proficiency, I know sad.
     > I'd like to hear other solutions for this problem, I am thinking
    of a regexp
     > that replaces special chars with the underscore; sounds pretty
    robust and
     > globally acceptable?

    I replace any non alpha chat with a hyphen, then replace two or more
    hyphens with one. Simple, but I would also include the date so that
    naming clashes are less likely (if it's applicable). So you might end
    up with something similar to this:


    Or if using the date is not applicable, you could get something like


    Richard Heyes
    HTML5 graphing: RGraph ( <> -
    updated 23rd May)
    PHP mail: RMail ( <>)
    PHP datagrid: RGrid (
    PHP Template: RTemplate (

    PHP General Mailing List (
    To unsubscribe, visit:

Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to