Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Weird error when re-naming image names :/

Quote Reply
Weird error when re-naming image names :/
Hi,

I'm trying to work on making so Thumb_Images will work with non-standard charachters (i.e things like éêèëÏÌÎïìîÖÔÒöôòÜÛÙ , - etc)

I've got the code working - and it renames the file fine

glinks_Links_Files:

( 3 records in total ) Save Result
ID ForeignColName ForeignColKey File_Name File_Directory File_MimeType File_Size File_URL
2 Image 9 aff-payment-step-2.jpg /home/linkssql/ultradev.com/www image/jpeg 64226 http://ultradev.com.nmsrv.com/ Edit Delete
3 Image 7 endKR_d3Ca.jpg /home/linkssql/ultradev.com/www image/jpeg 14655 http://ultradev.com.nmsrv.com/ Edit Delete
4 Image 8 00001ËéêèëÏÌÎï whatever.jpg /home/linkssql/ultradev.com/www image/jpeg 14655 http://ultradev.com.nmsrv.com/ Edit Delete

The one in red works (after I commented out my function) .. but the one in green doesn't work :/

glinks_Links:

7 ete color http://www.ultranerds.com admin 2006-04-28 2009-10-07
asdasdasd jjfjdsj andy@ultranerds.com 18 No Yes Yes Yes 0.00 0 0 2006-04-28 19:20:08 2009-10-07 01:44:10 2147483647 0 0 0 0 NULL 0 0 0 endKR_d3Ca.jpg 0.15 Edit Dele

The image itself is renamed, and works fine - but for some reason, the admin side of things just doesn't wanna show when I click "view" when modifying a record :/

This is what I see:

Quote:
Links: Error Viewing File

Cannot file file pointed to by ID: 7 and Column: Image

The code is:

Code:
# rename_file_with_odd_charachters(filename,table,field,id)
sub rename_file_with_odd_charachters {


my $file = $_[0]; # the fielname
my $table = $_[1] || 'Links';
my $field = $_[2];
my $ID = $_[3];

return;

if ($debug > 0) {

print $IN->header;
use Data::Dumper;
print Dumper(@_);

print qq|<br /><br />
FILE: $file <br />
Table: $table <br />
Field: $field <br />
ID: $ID <br />
|;

}

# if true, we have charachrers we don't want - so lets replace them
if ($_[0] =~ /[\&\[\]ÀÂÄàâäÇçÉÊÈËéêèëÏÌÎïìîÖÔÒöôòÜÛÙüûùA-Z?!;«»\(\)" ]/) {

# print $IN->header;

if ($debug > 0) {
print qq|<font color="red">We got a match </font> <br />|
}


my $image = ReadImageForConvert($ID,$field,$table);

my @split = split /\//, $image;
pop @split;
my $folder = join("/", @split);

# print qq|Ok, we got the image of $image <br />|;
my $old_filename = $image;
my $new_filename = GT::CGI->unescape($image);

$old_filename =~ s/$folder\///;
$new_filename =~ s/$folder\///;

$old_filename = GT::CGI->escape($old_filename);

my @file_split = split /\./, $_[0];
my $ext = $file_split[$#file_split];

$new_filename = generate_random_string(10) . ".$ext"; #tr{&[]ÀÂÄàâäÇçÉÊÈËéêèëÏÌÎïìîÖÔÒöôòÜÛÙüûùA-Z?!;«»()" }{ aaaaaacceeeeeeeeiiiiiioooooouuuuuua-z__________};

if ($debug > 0) {
print qq|<font color="red">$new_filename</font> <br />|
}

if ($debug > 0) {
print $IN->header;
}
print qq|
folder: $folder <br />
old filename : $old_filename
<br /> new filename: $new_filename
| if $debug > 0;


copy(qq|$folder/$old_filename|,qq|$folder/$new_filename|);
unlink(qq|$folder/$old_filename|);

$new_filename =~ s/^\d+\-//;

$DB->table("${table}_Files")->update( { File_Name => $new_filename }, { ForeignColKey => $ID } ) || die $GT::SQL::error;
$DB->table("${table}")->update( { $field => $new_filename }, { ID => $ID } ) || die $GT::SQL::error;


}

}

Any ideas?

TIA

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates