Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Software error: Read failure at test.pl
#!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use CGI::Carp qw(fatalsToBrowser); use LWP::UserAgent; use URI::URL; use HTTP::Request; use Image::Size; my $num_bytes = 1024; my $totalbytes; my ($bytesread,$buffer); my $img = ""; my @the_url = ('http://www.test.com/images/one.jpg', 'http://www.test.com/images/two.jpg', 'http://www.test.com/images/three.jpg', 'http://www.test.com/images/four.jpg',); my $hdrs = new HTTP::Headers(Accept => 'text/plain', UserAgent =>'Mega +Browser/1.0'); my ($url,$req,$ua,$resp); print header(); my $c=0; foreach my $urls(@the_url) { $c++; my @full_url = split(/(\\)|(\/)/,$urls); my $filename = pop(@full_url); $filename =~ s/\n//; $filename =~ s/\r//; $filename = "andrey"."_".$filename; $filename=lc($filename); $url = new URI::URL($urls); $req = new HTTP::Request('GET', $url, $hdrs); $ua = new LWP::UserAgent; $resp = $ua->request($req); if ($resp->is_success) { $img = $resp->content; open(IMAGE, ">../../img/$filename") or die "$!"; binmode IMAGE; while ($bytesread = read($img,$buffer,$num_bytes)) { $totalbytes += $bytesread; print IMAGE $buffer; } die "Read failure" unless defined($bytesread); close IMAGE or die "$!"; } } print "<br>Done<br>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FIle Upload Error Help!
by JavaFan (Canon) on Jul 21, 2011 at 18:55 UTC | |
by Anonymous Monk on Jul 21, 2011 at 19:15 UTC | |
by JavaFan (Canon) on Jul 21, 2011 at 19:26 UTC | |
by Anonymous Monk on Jul 21, 2011 at 19:34 UTC | |
by JavaFan (Canon) on Jul 21, 2011 at 19:46 UTC | |
by cdarke (Prior) on Jul 22, 2011 at 07:20 UTC |