473,466 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CGI upload creates empty file on server?

The script below uploads the selected file and creates it on the
server in the right directory and all looks fine. But the file is
empty, it contains nothing...

HTML FORM:
<form name="foo" method="post" action="../upload_image.pl"
target="_self" enctype="multipart/form-data">
<input type="file" name="file"><input type="text"
name="filename"></form>

Perl script:

#!/usr/bin/perl

use CGI;
use Cwd;

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

#Setup query from cgi
my $cgi = new CGI;

#Setup upload directory
$uploaddir = "/client_image_uploaddir";
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename");
$datestr = time;

#Handle the upload
open FHUP, ">$uploaddir/$file" or die;
binmode FHUP;

undef $Buffer;
while( read( $file, $Buffer, 1024 ) ){
print FHUP $Buffer;
}
close (FHUP);

print $cgi -> header();

print "<h3>Filen '$filename' blev uploaded!</h3>";
print "<img src=client_image_uploaddir/$file alt=$filename> ";
print "<a href=\"javascript:void(history.back());\">Tilbage</a> <a
href=\"javascript:void(window.close());\">Luk vindue</a>";

I also tried without 'buffering' and the result is the same, file is
created but with no content.

Any ideas?

/Kristian
Jul 19 '05 #1
1 6222
kr******@detandetfirma.dk (Kristian) wrote in message news:<c9**************************@posting.google. com>...
The script below uploads the selected file and creates it on the
server in the right directory and all looks fine. But the file is
empty, it contains nothing...

#!/usr/bin/perl
If you had used strict and warnings you would have got errors that
would have given you a clue as to what was wrong with your program.

Why do people stubbonly refuse to help themselves?
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;


The thing returned by param() for an upload field is magically both a
string and a file handle.

IMNSHO this was poor design in CGI. Consider using the upload method
for upload fields.

Anyhow, once you start to mess with the magic thing as a string, the
magic is lost and it becomes an ordinary string.

If you then try to use a the string as a filehandle then you'd usually
get an error. That's because _usually_ Perl5 scripts have "use
strict" at the top. If you leave out the "use strict" then (for
reasons of Perl4 compatability) the string is interpreted as a
symbolic reference to a file handle.

I suggest you find the person who advised you not to put "use strict"
at the top of your scripts, shake them warmly by the throat, and
explain how not doing so has wasted your time.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Ariel Dolan | last post by:
Can I use HtmlInputFile to only get the selected file name but not actually upload the file? Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile...
1
by: Alex | last post by:
I am having issues with a script to upload files from a client to a webserver. The problem is not with the actual upload but with where it uploads. The whole process is supposed to create a...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
2
chunk1978
by: chunk1978 | last post by:
hi there... i've written a small PHP script to upload files onto my server... but whenever i upload a file, the file size becomes automatically smaller on the server... for example: i uploaded a...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: poojamangal | last post by:
I want to upload images or pdf files. but i m unable to do so. i got error. please help me to sort it out.. my code is: <% 'on error resume next Class FreeASPUpload Public UploadedFiles...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.