Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Image uploads filing incorrectly in v2.1

(Page 3 of 3)
> >
Quote Reply
Re: [Payooo] Image uploads filing incorrectly in v2.1 In reply to
Well, I am not a Regex guru Blush

How to change this one so it doesn't allow images with spaces in the filename, but at the same time, it allows the field to be blank/empty?

^(?:|.*\.(?i:jpg|jpeg|jpe|gif))$


Thanks in advance!
Quote Reply
Re: [Payooo] Image uploads filing incorrectly in v2.1 In reply to
Quote:
so it doesn't allow images with spaces in the filename, but at the same time, it allows the field to be blank/empty?


Ever figure this one out?

Thanks!
Quote Reply
Re: [Swaylock] Image uploads filing incorrectly in v2.1 In reply to
Maybe late but...

^(?:|[\w-\.]+\.(?i:jpg|jpeg|jpe|gif))$

This will allow empty field (not required)
And if file exist it will allow all alphanumeric characters, "_", "-" and ".".
Quote Reply
Re: [Payooo] Image uploads filing incorrectly in v2.1 In reply to
In Reply To:
during the upload (via admin), the spaces are converted to %20's.

So, "image one.gif" is now "image%20one.gif".
A reply to this old post in case anyone else runs into this problem. There's two ways of accessing file column files:
1) Use jump.cgi: <%config.db_cgi_url%>/jump.cgi?ID=<%ID%>;view=FileColumnName (or use download=FileColumnName instead of view=... if you want it to be downloaded instead of viewed inline).
2) Write your own global like it has been done in this thread (note that your image directory has to be web accessible for this to work). With the spaces problem (it's actually any non 0-9a-z_.- character), it should have been fixed in Links SQL 2.1.0.

Adrian

Last edited by:

brewt: Jun 23, 2006, 1:50 PM
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
the spaces problem still exist
i'm using links sql 2.1.1

In Reply To:
In Reply To:
during the upload (via admin), the spaces are converted to %20's.

So, "image one.gif" is now "image%20one.gif".
A reply to this old post in case anyone else runs into this problem. There's two ways of accessing file column files:
1) Use jump.cgi: <%config.db_cgi_url%>/jump.cgi?ID=<%ID%>;view=FileColumnName (or use download=FileColumnName instead of view=... if you want it to be downloaded instead of viewed inline).
2) Write your own global like it has been done in this thread (note that your image directory has to be web accessible for this to work). With the spaces problem (it's actually any non 0-9a-z_.- character), it should have been fixed in Links SQL 2.1.0.
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
In Reply To:
the spaces problem still exist
i'm using links sql 2.1.1
I don't have a copy of 2.1.1 installed, but the 2.1.2 I have installed correctly returns the right filename when using File_RelativePath().

If you just use the <%FileColumnName%> tag, yes you will always get the unescaped filename.

Adrian
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
Fun resurecting old threads...

Regarding the spaces problem -- if someone tries to upload an image file with spaces in the name, what is the best way to handle that?
Quote Reply
Re: [Swaylock] Image uploads filing incorrectly in v2.1 In reply to
If you are retrieving the file correctly (eg. the two methods described in my post above), then you should have no problems dealing with the file.

However, with jump.cgi, it does make it lose its original filename (with everything except IE), so I'm going to fix that.

Adrian

Last edited by:

brewt: Jun 23, 2006, 4:33 PM
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
when someone tries to upload a file with spaces in it he will not be able to upload it. he will get an error

the solutions you sugested is not solving the problem. i'm still geting an error
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
You will only get an error with filenames with spaces if you put a regex on the field that doesn't allow spaces.

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
this one does not work
^(?:|[\w-\.]+\.(?i:jpg|jpeg|jpe|gif))$

what the correct format for regex that will allow spaces in the file name
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
In Reply To:
this one does not work
^(?:|[\w-\.]+\.(?i:jpg|jpeg|jpe|gif))$

what the correct format for regex that will allow spaces in the file name
This regex is intentionally written to disallow file with spaces in them because of the problem above which still exist.
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
Just add a space to the regex to allow spaces:
^(?:|[\w-\. ]+\.(?i:jpg|jpeg|jpe|gif))$

Adrian
Quote Reply
Re: [Payooo] Image uploads filing incorrectly in v2.1 In reply to
In Reply To:
This regex is intentionally written to disallow file with spaces in them because of the problem above which still exist.
How are spaces in filenames not working properly?

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
Taking another look at it, it won't work if you use the 2nd method, due to the escaping. Here's a global that will work with spaces:
Code:
sub {
my ($col, $id) = @_;
my $path = $DB->table(\'Links\')->file_info($col, $id)->File_RelativePath;
require GT::File::Tools;
my $file = $IN->escape(GT::File::Tools::basename($path));
$path = GT::File::Tools::dirname($path);
return "$path/$file";
}

So, for those wondering which method they should use:
The benefit of using method 1 is that the filenames of the file are kept the same on download (well, it works properly in IE, and will work properly in all browsers in the next release). For method 2, the filenames are the modified ones that contain the file id and the filenames are escaped. However, you can link directly to the files and so there's a little less overhead on retreiving the file.

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
i'm not a programmer, how can i add a space to the code, could you please post the full code with space in it?
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
I already did. Look at the post.

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
I just made a fix to GT::SQL::File that will allow the following code to work. This will be available in GLinks versions later than 3.1.0:

Code:
sub {
my ($col, $id) = @_;
return $DB->table(\'Links\')->file_info($col, $id)->File_URL;
}

This requires that you have the url set up correctly and the file's location is web accessible. I also added in a File_RelativeURL.

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
thanks this code does fix the space problem:

^(?:|[\w-\. ]+\.(?i:jpg|jpeg|jpe|gif))$

do we need to add GIF and JPG so if the file name is in capital letter it will allow it or is it not necessary?
Quote Reply
Re: [theguy] Image uploads filing incorrectly in v2.1 In reply to
The regex is case sensitive, so yes you do.

Adrian
Quote Reply
Re: [brewt] Image uploads filing incorrectly in v2.1 In reply to
In Reply To:
The regex is case sensitive, so yes you do.
This regex is case insensitive, so no need for uppercase extensions.
i - Do case-insensitive pattern matching.
Quote Reply
Re: [Payooo] Image uploads filing incorrectly in v2.1 In reply to
Oh, I wasn't looking closely at that regex, yes it has an embedded pattern-match modifier on the file extension part of the regex.

Adrian
> >