Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Form Regex - Gaps in file names

Quote Reply
Form Regex - Gaps in file names
Hi, I was using ^|.*\.(?i:gif|jpg|png)$ until I found out that any file type could be uploaded so I emailed support and Jack gave me ^([%\w-]+\.(?:jpe?g|JPE?G|gif|GIF|png|PNG)|)$ which works fine. I am finding most of my users are uploading files like 1a 2b.jpg and the gap/whitespace is giving them a error, how would I modify the above so that only images can be uploaded but the image can have any character in the filename including white space?
Quote Reply
Re: [garrynz] Form Regex - Gaps in file names In reply to
Hi,

Why would you *want* whitespace? Trust me, its a lot of grief, when people could just change it for an _ , or similar Pirate

I'd personally suggest just leaving it "as-is" Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Form Regex - Gaps in file names In reply to
Yeah I know ifs grief, when someone adds a site I manually change the filename myself to remove the whitespace. It's just that the majority of people adding there sites are small time B&B owners who arn't computer literate (one person uploaded a .doc file :/). So at the moment I want to make it as easy as possible for them to add their sites. Once my database builds up I will force them to change the filename. Any ideas on the regex?
Quote Reply
Re: [garrynz] Form Regex - Gaps in file names In reply to
Ah, fair enough. You could try;

^([%\w\s-]+\.(?:jpe?g|JPE?G|gif|GIF|png|PNG)|)$

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Form Regex - Gaps in file names In reply to
GSQL still saves files with the original filename. Why? There should be a way to save pics only with the ID and the extension or if you have more than one file with something like ID-Columname.Extension.

I think this should be a snap if someone knows where to change the script ... im still searching for the right place. ;-(

Have someone done this before?


BTW: Using regex: If you think your users are too stupid (i think so), it makes no sense to get on thier nerves with a lot of error-messages, so the add.cgi should take everything and rename it to something you can use without problems.
Quote Reply
Re: [Robert] Form Regex - Gaps in file names In reply to
Hi,

True (and that is how some of my custom upload routines work, using GT::CGI). However, GT::SQL::File seems adamant to use the ID-name.ext format, which as you say.. can be a REAL pain sometimes.

Maybe something for GT to consider in the next version? =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Form Regex - Gaps in file names In reply to
Unfortunalety i do my things normaly only in php, so i cant "speak" perl very well.
But i hope you could take a look into the scripts; everything we need is to find the right place
to change a variable.

Normaly it should go:

upload to temp
remember filename
***
insert link
copy to path/id-filename
insert filename into links_files

But it should be:

upload to temp
insert into links
remember filename, id
get extension (by mime not by filename)
get foreigncolname
copy to path/id-foreigncolname.extension
insert into links_files

Think this is no secret if someone could read this perl-stuff,
in php it would be a thing of minutes.

May you find this little time for us, please?
I really hate it to build and have to watch all data, remeber the id,
download, upload ...

Last edited by:

Robert: Oct 8, 2005, 4:19 AM
Quote Reply
Re: [Robert] Form Regex - Gaps in file names In reply to
Here's my two bits.

I would prefer if GT kept the filename as we upload it. At most they should convert wierd characters to _, but it's important to keep the file names in tact so that our images can continue to come up under google images which does look at the filenames for search results.

The only problem that can't be worked around is when deleting a filename that contains spaces. The system doesn't delete those files, and that's a GT bug.

peace.