Hi Monks!
I am trying to uplaod some pics from urls and I am getting an error on the "read(" in hte OPEN part of the code, I cant figure this one, can anyone take a look and tell why the read is not working, here is the error:
Software error: Read failure at test.pl

Here is the code:
#!/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>";

Thanks for Help!

In reply to FIle Upload Error Help! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.