Forum Moderators: coopster & phranque

Message Too Old, No Replies

why the system call isn't being excuted to rename my buffer

uploading files using perl

         

shaan1980

9:58 am on Feb 22, 2004 (gmt 0)

10+ Year Member



Hi
Iam a newbie to perl
I am writing a simple program to upload files into a directory . i get all my parameters through a web interface.
I upload the file into a buffer j and then i just want to rename that buffer into the original name of the file. Now Iam sure there is a better way to do this but please don't give me suggestions to redo my program. the code is pasted below everything in the file works except for the last system call to rename the file. any sugesstions as why its not working.

#!/usr/local/bin/perl -w
print "Content-type: text/html\n\n";

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

$query=new CGI;
$agendadir="/raid5/newhome/www/njicc/agenda";

$month=param("Month");
$day=param("Day");
$year=param("Year");
$file1 = param('file');
print ("$file1");
$file1 =~ s/.*[\/\\](.*)/$1/;
$newfilename="$month.$year.$day.AGENDA";
$DATA= $query->upload("file");
my $success = open OUTPUTFILE,">$agendadir/j";
unless($success){
print "Cannot open file";
}
binmode OUTPUTFILE;
while (<$DATA>)
{
print OUTPUTFILE;
}

print ("Iam out of the loop");
close OUTPUTFILE;
system("cp $agendadir/j $agendadir/$file1");

tombola

3:49 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



Welcome to Webmasterworld, shaan1980!

What if you replace the last line:

system("cp $agendadir/j $agendadir/$file1");

with this line:

`cp $agendadir/j $agendadir/$file1`;

Normally, they should both work.

shaan1980

5:20 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



I tried that already
for that matter any system(); calls
like system('mkdir /raid5/newhome/www/njicc/agenda/k');
this doesn't work too
are there any system settings needed to be done some library that I am not including
help

hyperbole

8:30 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



I assume you are working on a *nix server because you are using 'cp' to copy the file. I't may be that you need to use a fully qualified name like '/usr/local/bin/cp' execute the cp command.

andrew_m

8:51 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



That (the full path) and you said you want to rename -- why use cp for that? Use perl's internal rename() call.

Or

use File::Copy;
copy('file1','file2);

shaan1980

11:13 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



I have to check up with my sys admin as to whats going on because none of the suggestions work
thanks anyway guys in case I find something new I will try and post it

shaan1980

3:14 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



Hi guys in case you are still wondering it was a permissions problem on UNIX
we got it fixed