webscripter
Programmer
I'm trying to transfer an image and want to use LWP::Request so I can check the filesize and content-type.
The code compiles, but doesn't transfer the content.
I put alot of traces in and would rather not use mirror, or LWP::Simple. I need the files to transfer everytime and make sure the size and content-type are correct before writing the image.
Thankyou for your help.
Thanks
Pat
ideas@microwebber.com
The code compiles, but doesn't transfer the content.
I put alot of traces in and would rather not use mirror, or LWP::Simple. I need the files to transfer everytime and make sure the size and content-type are correct before writing the image.
Code:
my$i = 0;
foreach(@images){
if(/\w/){
# rename the images so they are harder to open
my$filename = $_;
#$filename =~ s/\./_/;
print STDERR "\n filename = $filename";
/(.*)\.(.*)\./;
my$field = $_; my$suffix = $_;
$field =~ s/\.(.*)//g; $suffix =~ s/(.*)\.//g;
print STDERR "\n field = $field";
print STDERR "\n suffix = $suffix";
my$path = "$domain/$catg/$sesn/$dir$filename";
my$url = "[URL unfurl="true"]http://$domain2$html/${demo}images/layout/$sesn/$dir$_";[/URL]
my$req = HTTP::Request->new(POST => $url);
my$response = $ua->request($req);
if($response->is_success){
print STDERR "\n content_type ".$response->content_type;
unless($response->content_type eq "image/$suffix"){
print STDERR "\n content-type is wrong ".$response->content_type;
next;
}
if($i == 0){
$i=1;
print STDERR "\n\n******************************\n".$response->content."\n******************************\n\n";}
if(open(IMAGE, ">./unchecked/$path")){
# binmode(*IMAGE);
lockit(*IMAGE,2);
print IMAGE $response->content;
unlockit(*IMAGE);
close(IMAGE);
print STDERR "\n Wrote ./unchecked/$path";
}else{
$done = 0;
print STDERR "\n**IMAGE** Couldn't write ./unchecked/$path";
print "\n <BR>**IMAGE** Couldn't write ./unchecked/$path";
}
my$content = $response->content;
$content =~ s@'@\'@g;
my$stmt = "INSERT INTO STYLE_PICTURES_${domain}_${catg}_$sesn WHERE $field='$response->content');";
#print STDERR "\n$stmt";
eval{
$pkg::dbh->do($stmt);
};
mysql_errors($stmt);
}else{
$done = 0;
print STDERR "Couldn't transfer $url".$response->status_line;
push(@pkg::messages, "Couldn't transfer $url ".$response->status_line);
}
}
}
Thankyou for your help.
Thanks
Pat
ideas@microwebber.com