freelanceprogrammers.org Forum Index » Perl

Another uploading problem


View user's profile Post To page top
kjhseka Posted: Sun Jul 03, 2005 3:56 am


Joined: 14 Jun 2004

Posts: 4
Another uploading problem
Hello,
I solved the previous problem, but I have a new one. I try to upload
an image in the filesystem rather than in a database, using the
following code (note I run Perl on Windows XP with Apache server):

my $name = param("name");
my $image = param("image");
my $img_data = upload("image");
my $img_buffer=``;

$name =~ s/^s+//;
$name =~ s/s+$//;

# Also work with while (<$image>); The upload("image") is not
really required.
# This is just an alternative to $image = param("image").
while(<$img_data>)
{
$img_buffer .= $_;
}

open(IMAGEFILE, ">images/$name.jpg");
print IMAGEFILE $img_buffer;
close(IMAGEFILE);


If I modify the script and try to upload the image in the database as
blob type rather than in the filesystem everything works and I can
see the image in my browser if I serve it with an appropiate
function. But if I run the code as is, the image will be uploaded...
But I cannot see it in my Windows Picture and Fax Viewer. If I try to
open this image with Adobe Phptoshop, I receive the following error:

"Could not open "pathimage.jpg" because invalid DQT JPEG QTable
number is found (it must be 4)"

I also tried to open it with another graphical software, but I
receive:
"Unknown file format" error.

Obviously, there is something incorrect in my code. Perhaps there is
some CR/LF corruption and the image is not properly parsed, perhaps I
should to escape $_ before fill $image_buffer, perhaps I must specify
some mime-type in a way that I ignore...

Some one can give my any idea?

Thanks a lot
Alph
Reply with quote
Send private message
View user's profile Post To page top
nottherat Posted: Sun Jul 03, 2005 7:24 pm


Joined: 03 Jul 2005

Posts: 15
Another uploading problem
kjhseka <> wrote:

[snip]

: Obviously, there is something incorrect in my code. Perhaps there is
: some CR/LF corruption and the image is not properly parsed, perhaps I
: should to escape $_ before fill $image_buffer, perhaps I must specify
: some mime-type in a way that I ignore...
:
: Some one can give my any idea?

Have you tried uploading using the perl binmode() function? It
changes the way line endings are processed on systems which distinguish
between binary and text files.

perldoc -f binmode (or look in perlfunc in the HTML docs.)


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help