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. -
#!/usr/bin/perl -w
-
-
use CGI;
-
-
my $cgi = new CGI;
-
-
my $file = $cgi->param('file');
-
my $fileName = $cgi->param('file');
-
-
-
-
@types = ("jpg", "gif");
-
my ( $type_ok, $file_contents, $buffer);
-
-
@sitess=("site1", "site2");
-
-
foreach $sitess (@sitess){
-
-
print "Content-type: text/html\n\n";
-
-
# get the extension
-
my @file_type = split(/\./, $fileName);
-
# we can assume everything after the last . found is the extension
-
my $file_type = $file_type[$#file_type];
-
-
# get the file name, this removes everything up to and including the
-
# last slash found ( be it a forward or back slash )
-
$fileName =~ s/^.*(\\|\/)//;
-
-
# remove all spaces from new instance of filename var
-
$fileName =~ s/\s+//ig;
-
-
# check for any any non alpha numeric characters in filename (allow dots and dahses)
-
$fileName =~ s/\./PsJsDoT/g;
-
$fileName =~ s/\-/PsJsDaSh/g;
-
if($fileName =~ /\W/){
-
$fileName =~ s/\W/n/ig; # replace any bad chars with the letter "n"
-
}
-
$fileName =~ s/PsJsDoT/\./g;
-
$fileName =~ s/PsJsDaSh/\-/g;
-
-
# if $file_type matches one of the types specified, make the $type_ok var true
-
for($b = 0; $b < @types; $b++){
-
-
if($file_type =~ /^$types[$b]$/){
-
$type_ok++;
-
}
-
if($types[$b] eq "ALL"){
-
$type_ok++; # if ALL keyword is found, increment $type_ok var.
-
}
-
}
-
$overwrite=1;
-
# if ok, check if overwrite is allowed
-
if($type_ok){
-
-
open ( UPLOADFILE, ">/$sitess/path/$fileName" ) or die "$!";
-
binmode UPLOADFILE;
-
#$VAR{err} .= $!;
-
while (read($file, $buffer, 1024))
-
{
-
print UPLOADFILE $buffer;
-
}
-
-
close UPLOADFILE;
-
-
print "<font color=\"red\">hi</font></p>";
-
-
print "<p>$fileName :: <a href=\"http://www.$sitess.com/$fileName\"><img src=\"http://www.$sitess.com/$fileName\"></a></p>";
-
-
}
-
-
}
-
-
1;
-
1 2093 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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....
|
by: Rookie |
last post by:
Is C an object oriented programming language?
|
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...
|
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.
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |