Re: Web friendly file names

From: Date: Wed, 03 Jun 2009 16:39:42 +0000
Subject: Re: Web friendly file names
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-293546@lists.php.net to get a copy of this message
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? Skip 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 <richard@php.net <mailto:richard@php.net>> wrote:
    Hi,
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
    friendly.
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:
    /product/2009/06/03/24ct-gold-earrings
    Or if using the date is not applicable, you could get something like
    this:
    /product/24ct-gold-earrings
    --
    Richard Heyes
    HTML5 graphing: RGraph (www.rgraph.net <http://www.rgraph.net> -
    updated 23rd May)
    PHP mail: RMail (www.phpguru.org/rmail <http://www.phpguru.org/rmail>)
    PHP datagrid: RGrid (www.phpguru.org/rgrid
    <http://www.phpguru.org/rgrid>)
    PHP Template: RTemplate (www.phpguru.org/rtemplate
    <http://www.phpguru.org/rtemplate>)
    PHP SMTP: http://www.phpguru.org/smtp
    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
-- ==================================== Skip Evans Big Sky Penguin, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://bigskypenguin.com ------------------------------------ Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut

« previous php.general (#293546) next »