in reply to Re: FIle Upload Error Help!
in thread FIle Upload Error Help!

But at this point in read if I use the file handle it will have no value because the image file is in $img</cope> and not in the <code>$filename variable. How would you do it?

Replies are listed 'Best First'.
Re^3: FIle Upload Error Help!
by JavaFan (Canon) on Jul 21, 2011 at 19:26 UTC
    I've no idea what is in $img, other than it's a string. Perhaps all you want is:
    $url = new URI::URL($urls); $req = new HTTP::Request('GET', $url, $hdrs); $ua = new LWP::UserAgent; $resp = $ua->request($req); if ($resp->is_success) { open(IMAGE, ">../../img/$filename") or die "$!"; binmode IMAGE; print IMAGE $resp->content; }
    But then you may want to use LWP::Simple instead.
      That I know works, I tried as well but I would like to read this image file before using the code inside of the while loop. Just in case the image been uplaoded is too big. The $img has the image itself from the urls.
        So, you're assuming that read is some magical function which you can feed a URL? Where did you get that idea from? And if you think that you can feed read a URL, why didn't you try to read to fetch the document containing the URL to the image?

        I'd use LWP::Simple and its getprint method. That will take a URL, and write it to the selected filehandle. Which is what you want.

        I would like to read this image file before using the code inside of the while loop. Just in case the image been uplaoded is too big

        Not a good way of finding out the file size, the simplest is to use -s. For example:
        my $size = -s IMAGE;
        or :
        my $size = -s $filename;