473,390 Members | 1,323 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,390 software developers and data experts.

object oriented programming : Upload file to multiple sites

Hi, I am very new to "object oriented programming". I have this script which I didn't write but have altered and have been using for a while to allow people to upload files to a website. Now I am trying to adapt the same script to upload files to multiple websites specified in an array. This is for a content management system for our websites. I thought I could just stick a foreach loop round most of the script and that would work. However, no matter what I do, I get one file uploaded and the next file is created but has no content. I have been trying to upload image files but the script should work with all files as required, including .pl perl files. Just to make it clear, I get the correct image file in all websites but only the first one in the @sitess array actually has been uploaded, the others have no content and are zero bytes in size.

Any help very much appreciated. Thanks very much.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use CGI;
  4.  
  5. my $cgi = new CGI;
  6.  
  7. my $file = $cgi->param('file');
  8. my $fileName = $cgi->param('file');
  9.  
  10.  
  11.  
  12. @types = ("jpg", "gif");
  13. my ( $type_ok, $file_contents, $buffer);
  14.  
  15. @sitess=("site1", "site2");
  16.  
  17. foreach $sitess (@sitess){
  18.  
  19. print "Content-type: text/html\n\n";
  20.  
  21.     # get the extension
  22.     my @file_type   = split(/\./, $fileName);
  23.     # we can assume everything after the last . found is the extension
  24.     my $file_type   = $file_type[$#file_type];
  25.  
  26.     # get the file name, this removes everything up to and including the 
  27.     # last slash found ( be it a forward or back slash )
  28.     $fileName =~ s/^.*(\\|\/)//;
  29.  
  30.     # remove all spaces from new instance of filename var 
  31.     $fileName =~ s/\s+//ig;
  32.  
  33.     # check for any any non alpha numeric characters in filename (allow dots and dahses)
  34.     $fileName =~ s/\./PsJsDoT/g;
  35.     $fileName =~ s/\-/PsJsDaSh/g;
  36.     if($fileName =~ /\W/){
  37.         $fileName =~ s/\W/n/ig; # replace any bad chars with the letter "n"
  38.     }
  39.     $fileName =~ s/PsJsDoT/\./g;
  40.     $fileName =~ s/PsJsDaSh/\-/g;
  41.  
  42.     # if $file_type matches one of the types specified, make the $type_ok var true
  43.     for($b = 0; $b < @types; $b++){
  44.  
  45.         if($file_type =~ /^$types[$b]$/){
  46.             $type_ok++;
  47.         }
  48.         if($types[$b] eq "ALL"){
  49.             $type_ok++; # if ALL keyword is found, increment $type_ok var.
  50.         }
  51.     }
  52.     $overwrite=1;
  53.     # if ok, check if overwrite is allowed
  54.     if($type_ok){
  55.  
  56.     open ( UPLOADFILE, ">/$sitess/path/$fileName" ) or die "$!"; 
  57. binmode UPLOADFILE; 
  58. #$VAR{err} .= $!;
  59. while  (read($file, $buffer, 1024)) 
  60.  print UPLOADFILE $buffer; 
  61.  
  62. close UPLOADFILE; 
  63.  
  64. print "<font color=\"red\">hi</font></p>";
  65.  
  66. print "<p>$fileName :: <a href=\"http://www.$sitess.com/$fileName\"><img src=\"http://www.$sitess.com/$fileName\"></a></p>";
  67.  
  68. }
  69.  
  70. }
  71.  
  72. 1;
  73.  
Sep 2 '08 #1
1 2092
KevinADC
4,059 Expert 2GB
see tek-tips
Sep 3 '08 #2

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

Similar topics

6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
5
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
34
by: Pmb | last post by:
Hi. I'm new to this group. I'm refreshing/learning C++ and am starting to learn Object Oriented Programming (OOP). In discussing this with people I came up short as to what the benefits of OOP are....
14
by: Rookie | last post by:
Is C an object oriented programming language?
4
by: scottrm | last post by:
I am fairly new to oo design and I am looking at developing an object oriented asp.net application which will be built on top of a relational database. I have read quite a bit of the theory but...
73
by: Water Cooler v2 | last post by:
I am new to PHP, just one day new. But I am otherwise a seasoned programmer on many other languages like C, VB 6, C#, VB.NET, Win32 platform and have some tiny bit experience in MFC, C++, Python. ...
47
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.