Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Upload a file on server

Reply
Thread Tools

Upload a file on server

 
 
pjsenthil@gmail.com
Guest
Posts: n/a
 
      08-08-2006
Hi
I have to upload a file on to a server.I have tried it.

In my form of an HTML page, if i have a input file type ( file browse
element) it is working properly.and i am able to upload.


But in my case.I have so many images .i will list in the the browser
with check box for each and image preview for each.The user will check
the multiple check boxs and will upload.

if i am trying out this. i am not able to upload the file on the
server.
the problem wat i am facing is,...

the below is partial code...
-------------------------------------------------------

if($type_ok){
if(!$overwrite){ # if $overwite = 0 or flase, rename file using the
checkex sub

$fileName = check_existence($destination,$fileName);
}
# create a new file on the server using the formatted ( new instance
) filename

$r[$cnt]=$file;
$cnt++;
if(open(NEW, ">$destination$S{S}$fileName")){
$VAR{err} .= $!;

if($isWIN){ binmode NEW; } else { chmod(0777,
"$destination$S{S}$fileName"); }
# start reading users HD 1 kb at a time.

%note if the data from file browse it is working well..

but in case of check box .then the below read function is not working..
i have checked that $file value...it is getting the path of the source
perfectly.
****the problem is it not going into the while loop %

while(read($file, $buffer, 1024))
{

print NEW $e;
}
# close the new file on the server and we're done
close NEW;
} else {
# return the server's error message if the new file could not be
created
return qq~Error: Could not open new file on server. $!~;
}

# check limit hasn't just been overshot
if(-s "$destination$S{S}$fileName" > $limit){ # -s is the file size
unlink("$destination$S{S}$fileName"); # delete it if it's over the
specified limit

return qq~File exceeded limitations : $fileName~;
}
} else {

return qq~Bad file type : $file_type~;
}
if(-s "$destination$S{S}$fileName"){

return qq~Success $fileName~; #success
} else {
unlink("$destination$S{S}$fileName");


return ; qq~Upload failed : No data in $fileName. No size on server's
copy of file.
Check the path entered. $VAR{err}~;
}
-------------------------------------------

i have written the comments with in the code above..as (%-------%).


So can one suggest me wat problem it can be,.
pl

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      08-08-2006
wrote in
news: oups.com:

> But in my case.I have so many images .i will list in the the browser
> with check box for each and image preview for each.


This is not a Perl question. You are understanding of CGI is lacking.

To be able to create a form with a thumbnail for each image, you need to
upload each image to the server.

Or, use a signed Java applet or Activex object. Check out how online
photo stores do it.

(Yes, one could ask the user for a directory to browse on the hard drive,
then trust client-side Javascript to display such thumbs, or create and
serve an HTML document with links to images on the user's hard drive,
but I would not even consider it for obvious security issues).

> the below is partial code...


This code is worse than useless in that it creates the distinct
impression that you don't have the foggies idea what you are doing.

You should post a small script that others can run just by copying and
pasting.

If you want to insert extended comments in the middle of the script, just
use

=for usenet

blah blah blah

=cut

> # start reading users HD 1 kb at a time.


I won't be visiting your site soon!

> while(read($file, $buffer, 1024))
> {
>
> print NEW $e;
> }



You probably want sysread and syswrite. However, you would do yourself a
favor by reading about uploading in the CGI.pm manual even if you end up
not using CGI.pm.

> # close the new file on the server and we're done
> close NEW;


By the way, this is exactly the kind of place where you should put a
limit on POSTs, check if every single output operation succeded, if close
succeded etc.

I don't understand any part of the code below, presumably because it is
missing crucial parts and it is formatted awfully.

> } else {
> # return the server's error message if the new file
> could not be
> created
> return qq~Error: Could not open new file on server.
> $!~;
> }
>
> # check limit hasn't just been overshot
> if(-s "$destination$S{S}$fileName" > $limit){ # -s is the
> file size
> unlink("$destination$S{S}$fileName"); # delete it if
> it's over the
> specified limit
>
> return qq~File exceeded limitations : $fileName~;
> }
> } else {
>
> return qq~Bad file type : $file_type~;
> }
> if(-s "$destination$S{S}$fileName"){
>
> return qq~Success $fileName~; #success
> } else {
> unlink("$destination$S{S}$fileName");
>
>
> return ; qq~Upload failed : No data in $fileName. No size on
> server's
> copy of file.
> Check the path entered. $VAR{err}~;
> }
> -------------------------------------------
>
> i have written the comments with in the code above..as (%-------%).


Don't. Why make it harder for people to help you?


> So can one suggest me wat problem it can be,.


Learn about CGI in general. Read the posting guidelines for this group,
and conform to them.

Sinan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload from client application (non-form based upload) stuart@microsoft.com Python 1 11-25-2006 12:14 AM
Upload a file without file Upload control - ASP.Net =?Utf-8?B?U2FyYXY=?= ASP .Net 3 08-03-2005 01:09 AM
How to detect sizeof upload in order to show status of browser file upload? Heather Fraser Java 0 07-05-2004 12:35 AM
File upload servlet using MultipartRequest - file not created on the server Paul Smith Java 1 11-17-2003 10:24 AM
Upload Excel with Macros using HTML File Upload Prakash ASP General 3 11-12-2003 04:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57