Gossamer Forum
Quote Reply
Image upload space issue
Hello all,

I am using global imageurl to let people upload their logo or image as needed. I am running into people who do not know how to properly format an image name. (no spaces). SO when someone uploads an image with a space in the name the image does not shows up.

Does anyone have any suggestions on how to fix this issue?
Code:
sub {
my $field = shift;
my $tags = GT::Template->tags;
my $id = $tags->{ID};
if ($tags->{$field})
{

my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( "$field", $id );
return "" unless($fh);

my $location = $fh->File_RelativePath;
my $logow = 75;
my $extra_atts="oriw=$tags->{LogoWidth}";
if($field eq "Logo" && $tags->{LogoWidth} ne "$logow"){
eval{
use Image::Magick;
};
$@ and return $@;

my $i= new Image::Magick();
my $if = $CFG->{build_root_path} . "/upload$location";

my $error = $i->Read($if);
return "Could not read $if file. Reason:" . $error if $error;

my $w = $i->Get('width');
$extra_atts .= ";width =$w";
if($w ne "$logow"){
my $h = $i->Get('height');

my $logoh = int($h*($logow/$w));
$error = $i->Resize(geometry => "${logow}x$logoh", width => $logow, height => $logoh);
return "Could not read $if file. Reason:" . $error if $error;
$extra_atts .= ";height=$h";
my $rs = $i->Write($if);

}

$links_db->update({LogoWidth => $logow},{ID => $id}) if($tags->{LogoWidth} ne "$logow");

}


return qq~$CFG->{build_root_url}/Upload_Image$location~;
}
else
{
return "";
}
}
The form used:
<input class="text" type="file" id="Upload_Image" name="Upload_Image" value="" size="30">


Thanks for any help on this :)


Sandra Roussel
Chonsa Group Design - Fresh Start Housing

Last edited by:

SandraR: Feb 8, 2007, 9:19 PM
Quote Reply
Re: [SandraR] Image upload space issue In reply to
If you follow the instructions in the File column howto, filenames with spaces should be handled properly.

Adrian
Quote Reply
Re: [brewt] Image upload space issue In reply to
I may be tired but I saw no solution to the spaces issue.
Can you elaborate.

I am up-to-date for versions so that is not an issue.

Thanks


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
Hey brewt this did not work -- is there another solution?

Thanks
SandraR


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
Status:
I Changed the File Save Method from Simple to HASHED as described on the other thread, then I uploaded the image it worked correctly (BUT), it created a new folder called 0 and all the other uploaded images no longer show up.

I have yet to get the global and tag to work for the method you prescribed.

Any other suggestions would be greatly appreciated.

Thanks



Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
Yeah, changing from one file save method to another won't work too well since it will be looking for the files in the wrong place. I'll have to test everything using the simple file save method to make sure it works properly.

Adrian
Quote Reply
Re: [SandraR] Image upload space issue In reply to
You should check the path that the code gives you back when you call File_RelativePath. Make sure that it's the correct compared to the actual file on disk. There may be a problem where it returns a unescaped filename, while it is url escaped on disk.

Adrian
Quote Reply
Re: [brewt] Image upload space issue In reply to
Hello Adrian,

Well I tried it every which way, the tags are showing correctly, the global is working right, calling the image is the issue.

My server is not acknowledging the image:

http://freezone.ssan.com/Upload_Image/0/80-star01%20purple.gif

I see it in the folder when linking the path is correct, but it sends me to my 404 page.

I know its a simple answer but I am brain dead.

Thanks for you help.





Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
It looks like it's being redirected. Is there a problem with a rewrite rule?

Adrian
Quote Reply
Re: [brewt] Image upload space issue In reply to
Rewrite is not an issue -- the only issue, which started this thread is spaces in image uploads.
Everything is still working fine as long as images are not uploaded with spaces.


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
Yes, and my question is your rewrite rule rewriting the url when it shouldn't be?

Adrian
Quote Reply
Re: [brewt] Image upload space issue In reply to
Adrian,

Did you get it to work using Simple instead of Hashed?


Sandra Roussel
Chonsa Group Design - Fresh Start Housing
Quote Reply
Re: [SandraR] Image upload space issue In reply to
I took another look at your code and the generated URL and realized the mistake.

The line here:
Code:
return qq~$CFG->{build_root_url}/Upload_Image$location~;
is incorrect as it uses $location (which is from File_RelativePath). This is fine for direct access to the file from the file system, but is wrong for access from the web. You need to use a call to File_RelativeURL for the correct url. You can also just can $IN->escape($location) as well.

Adrian
Quote Reply
Re: [brewt] Image upload space issue In reply to
Hello Adrian,


You are not going to believe it but I finally got it to work with one exception -- It still refuses to show up on the page.

When I modify the link and click View (Upload_Image download view Delete)
it shows up fine but the darned image still refuses to show up on the page, if you upload an image without the spaces it shows up fine.

global modified
Code:
sub {
my $field = shift;
my $tags = GT::Template->tags;
my $id = $tags->{ID};
if ($tags->{$field})
{

my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( "$field", $id );
return "" unless($fh);

my $location = $fh->File_RelativePath;
my $logow = 75;
my $extra_atts="oriw=$tags->{LogoWidth}";
if($field eq "Logo" && $tags->{LogoWidth} ne "$logow"){
eval{
use Image::Magick;
};
$@ and return $@;

my $i= new Image::Magick();
my $if = $CFG->{build_root_path} . "/Upload_Image/";

my $error = $i->Read($if);
return "Could not read $if file. Reason:" . $error if $error;

my $w = $i->Get('width');
$extra_atts .= ";width =$w";
if($w ne "$logow"){
my $h = $i->Get('height');

my $logoh = int($h*($logow/$w));
$error = $i->Resize(geometry => "${logow}x$logoh", width => $logow, height => $logoh);
return "Could not read $if file. Reason:" . $error if $error;
$extra_atts .= ";height=$h";
my $rs = $i->Write($if);

}

$links_db->update({LogoWidth => $logow},{ID => $id}) if($tags->{LogoWidth} ne "$logow");

}


return qq~$CFG->{build_root_url}/Upload_Image/~;
}
else
{
return "";
}
}

Thanks for you help


Sandra Roussel
Chonsa Group Design - Fresh Start Housing