473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Uploading Image(jpg) Files Using CGI- Problem

Hi All,
Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it doesn't works on IE.

Please, help me out as I am new to this and would be highly thankful if anyone has running code for uploading image files to the server using CGI either Perl or C.

This code i took it from net only.

#!/usr/bin/perl -w

use strict;
use CGI;
use CGI qw(:standard);

print "Content-type: text/html\n\n";

print "Preparing to upload your image. Must be type jpg and LE 1M. ";

my $query = new CGI;

print "step 1";
my $file= $query->param('uploadfile');

print $file;

print "step 2";
my $info= uploadInfo ($file);

print "step 3";
my $type= $info -> {'Content-Type'};
$file =~ s/.*[\/\\](.*)/$1/;

if ($file) {

# open (UPLOAD, ">C:/vps-va/uploadphoto/$file") || Error ();
open (UPLOAD, "> /usr/webserver/ws031202/web/cgi-bin/$file") || Error ();

binmode UPLOAD;

my $info = uploadInfo($file);
my $type= $info->{'Content-Type'};

print "<p>You want to upload
<b>$file</b> with a MIME type of

if ($file =~ /\.jpg/ or $file =~ /\.JPG/ ) {

print "<p>starting to upload";
my ($data, $length, $chunk);
while ($chunk = read ($file, $data, 16384)) {
print "in loop";
print UPLOAD $data;

$length += $chunk;
print "length is";
print $length;
if ($length > 1024000) {
print "<p> That image is too big. The limit is 1 Meg. I'm deleting.";
# unlink ("C:/vps-va/upload/$file") || Error2 ();
unlink ("/usr/webserver/ws031202/web/cgi-bin/$file") || Error2 ();
close (UPLOAD);
print ("<p> Upload of $file was successful. Size was $length bytes.");

} else {

print "<p>Must be jpg. Image not uploaded.";
unlink ("/usr/webserver/ws031202/web/cgi-bin/$file") || Error2 ();
} else {
print "<p> No file was chosen.";

sub Error {
print "Error routine 2.1 could not open";
print "Couldn't open temporary file: $!";
sub Error2 {
print "Couldn't delete file: $!";
sub Error3 {
print "Bad Password";


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<HTML [5]>
<FORM ACTION="/cgi-bin/upload2.cgi" METHOD="post" ENCTYPE="multipart/form-data">
Image to upload:......
<INPUT TYPE="file" NAME="uploadfile" size="50">
<input type="submit" name="Submit" value="Submit Form">

Thanks And Regards
Jan 18 '07 #1
2 5904
1,892 Expert 1GB
I moved your post to the Perl forum.
Jan 18 '07 #2
4,059 Expert 2GB
read the CGI documentation:


there are more up to date methods for uploading files and tracking the file size and etc, than the script you posted.
Jan 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular...
by: rbt | last post by:
Has anyone used pure python to upload files to a webdav server over SSL? I have no control over the server. I can access it with all of the various webdav GUIs such as Konqueror, Cadaver, etc. by...
by: Dave Navarro | last post by:
I am using some free Upload code by Jacob Gilley: ''*************************************** '' File: Upload.asp '' Author: Jacob "Beezle" Gilley '' Email: avis7@airmail.net '' Date: ...
by: Léopold VALLAURI | last post by:
Hi I have an Access file where is stored some JPG picture in an OLE Field Picture are stored with data added for OLE management.in the field but this data are different for each picture ! I...
by: marfi95 | last post by:
Hi all, I'm trying to do what I consider to be a fairly simple task, yet I'm having a heck of a time getting it to work. I'm trying to upload a file (without user intervention and a browser)...
by: Dean Richardson | last post by:
Hi, I'm having trouble uploading files via a PHP script. Whenever I upload a file greater than 10K, the file gets corrupted. However, text files upload OK. When I check the FTP Server log I...
by: Milsnips | last post by:
Hi there, this is my situation: i have a webpage with a photo gallery, when i am uploading files sometimes it takes a while, and when i open another browser window to view the photo gallery...
by: kestrel | last post by:
ive seen it done, but i dont know how to do it image.jpg?text=test then the text on the image changes, how is this done?
by: Kunal Nandi | last post by:
can any one give me the code for uploading and retriving image using Blob, with jsp at front end and oracle8i at the back end ??????? i have tried this using long raw datatype i was able to upload...
by: fiend | last post by:
I have an image (.jpg/.bmp) to be encrypted in C#.NET. The same encrypted image has to be Decrypted in Java. Any help on this is appreciated.
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.