powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

Ok, Gurus and Monks I need your wisdom, yet again :o(

I'm trying to upload a image file, here is my code:
$file_name_to_add = $in{up_banner}; $file_name_to_add =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; $ctype = $in{up_banner}; $ctypeb = $in{up_banner}; if ($ctype =~ /([^\/\\]+)$/) {#check if it as \ and / for valid path; $file_name_to_add = $1; $file_name_to_add =~ s/^\.+//; #remove the unwanted / or \ } # Check for File Extensions... (I'm renaming the uploaded # file to a database name that I've retrieved and stored # in the variable $record_id if ($file_name_to_add =~ m/\.gif$/i) { $file_ext = ".gif"; } elsif ($file_name_to_add =~ m/\.jpg$/i) { $file_ext = ".jpg"; } elsif ($file_name_to_add =~ m/\.jpeg$/i) { $file_ext = ".jpg"; } elsif ($file_name_to_add =~ m/\.png$/i) { $file_ext = ".png"; } else { $file_ext = ".gif"; # Default } $record_id .= $file_ext; # Append with the extension. open(OUT,">/home/user/dir/aff/pics/$record_id") or error("Can't open o +utfile (/home/user/dir/aff/pics/$record_id) for writing: $!"); $flen = 0; while (read($ctypeb,$i,1024)) { print OUT $i; $flen = $flen + 1024; } close(OUT); $page_content .= qq~ Length: ,$flen/1024,Kb<br />\n File was saved as $record_id!<br />\n<br />~;

So when it uploads the file, it gets the proper name, but then it's an empty file. 0 size. So it's not really writing the image to the file.

Any Ideas?

thx,
Richard

Replies are listed 'Best First'.
Re: Uploading a image...
by powerhouse (Friar) on Feb 02, 2003 at 07:45 UTC
    I've looked everywhere for "how to update a post" but cannot find it ANYWHERE. COME OUT, COME OUT WHEREVER YOU ARE :o)

    Ok just to let everyone know, I got it to work, I change the part that wrote the file to this:
    open (OUTFILE,">/home/user/site/aff/pics/$record_id"); while ($bytesread=read($ctypeb,$buffer,1024)) { print OUTFILE $buffer; }

    That worked.

    Can someone please tell me how to UPDATE a post once I've made it?

    thx,
    Richard
      Look at turnstep's home page.
      Search for "Which top-level nodes *are* editable?"
      Root nodes in SoPW are not editable, sorry.
      HTH

      cchampion
        Cool, thanks everyone. I was getting soooo frustrated, I read tons of pages, and lots of links, but never found the right one.

        Thanks again,
        Richard.

      You can update a post by making a request to Editor Requests.

      Where do you want *them* to go today?