Perl code Question -
am 28.09.2007 19:30:10 von brantzdr
I need to upload a file to the server and I have that working, but I
want to add the form# to the front of the file:
I can do this to the filename stored in Mysql but how do I change the
name of the file being uploaded to the server?
-
The variable for form number is $p
I thought I could do this somewhere in this part of the code?
sub Get_File_Name{
if ($ENV{HTTP_USER_AGENT}=~/win/i){
fileparse_set_fstype("MSDOS");
}
elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
fileparse_set_fstype("MacOS");
}
my $full_name = shift;
$full_name = basename($full_name);
$full_name =~ s!\s!\_!g;
return($full_name);
}
sub Store_File{
my $file_handle = shift;
my $file_name = shift;
my $data;
#my $mime = uploadInfo($File_handle)->{'Content-Type'};
open (STORAGE, ">$dir/$file_name")
or die "Error: $!\n";
#if($mime !~ /text/){
binmode ($file_handle);
binmode (STORAGE);
#}
while( read($file_handle, $data, 1024) ){
print STORAGE $data;
}
close STORAGE;
}
--
Douglas Brantz
Computer consultant
College of Fine & Applied Arts
Appalachian State University
Boone, NC 28608
828-262-6549 office
828-262-6312 - fax
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Question -
am 28.09.2007 19:54:06 von Greg Meckes
Couldn't you just say?:
open (STORAGE, ">$dir/$p$file_name")
--- Douglas Brantz wrote:
> I need to upload a file to the server and I have that working, but I
> want to add the form# to the front of the file:
> I can do this to the filename stored in Mysql but how do I change the
> name of the file being uploaded to the server?
> -
> The variable for form number is $p
>
> I thought I could do this somewhere in this part of the code?
>
> sub Get_File_Name{
> if ($ENV{HTTP_USER_AGENT}=~/win/i){
> fileparse_set_fstype("MSDOS");
> }
> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
> fileparse_set_fstype("MacOS");
> }
> my $full_name = shift;
> $full_name = basename($full_name);
> $full_name =~ s!\s!\_!g;
> return($full_name);
> }
> sub Store_File{
> my $file_handle = shift;
> my $file_name = shift;
> my $data;
> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
> open (STORAGE, ">$dir/$file_name")
> or die "Error: $!\n";
> #if($mime !~ /text/){
> binmode ($file_handle);
> binmode (STORAGE);
> #}
> while( read($file_handle, $data, 1024) ){
> print STORAGE $data;
> }
> close STORAGE;
> }
>
> --
> Douglas Brantz
> Computer consultant
> College of Fine & Applied Arts
> Appalachian State University
> Boone, NC 28608
>
> 828-262-6549 office
> 828-262-6312 - fax
>
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>
>
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Question -
am 28.09.2007 20:16:02 von brantzdr
That didn't seem to work - still uploads file with original name. In the
example I upload 1 file and form# 405 is added to the beginning of the
file name for Mysql -
below the list you see the File that is getting uploaded.
current: 405File1faapage.pdf
proposed:
syll1:
syll2:
csheet:
psheet:
File being uploaded: File1faapage.pdf
------------------------------------------------------------ ---------------------------
Greg Meckes wrote:
> Couldn't you just say?:
>
> open (STORAGE, ">$dir/$p$file_name")
>
>
>
> --- Douglas Brantz wrote:
>
>
>> I need to upload a file to the server and I have that working, but I
>> want to add the form# to the front of the file:
>> I can do this to the filename stored in Mysql but how do I change the
>> name of the file being uploaded to the server?
>> -
>> The variable for form number is $p
>>
>> I thought I could do this somewhere in this part of the code?
>>
>> sub Get_File_Name{
>> if ($ENV{HTTP_USER_AGENT}=~/win/i){
>> fileparse_set_fstype("MSDOS");
>> }
>> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
>> fileparse_set_fstype("MacOS");
>> }
>> my $full_name = shift;
>> $full_name = basename($full_name);
>> $full_name = "$p$full_name"; ##>> Added this so I can get the file name with form# for Mysql
>>
>> $full_name =~ s!\s!\_!g;
>> return($full_name);
>> }
>> sub Store_File{
>> my $file_handle = shift;
>> my $file_name = shift;
>> my $data;
>> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
>> open (STORAGE, ">$dir/$file_name") ## Tried "..>$dir/$p$file_name"); but it didnt' work.
>> or die "Error: $!\n";
>> #if($mime !~ /text/){
>> binmode ($file_handle);
>> binmode (STORAGE);
>> #}
>> while( read($file_handle, $data, 1024) ){
>> print STORAGE $data;
>> }
>> close STORAGE;
>> }
>>
>> --
>> Douglas Brantz
>> Computer consultant
>> College of Fine & Applied Arts
>> Appalachian State University
>> Boone, NC 28608
>>
>> 828-262-6549 office
>> 828-262-6312 - fax
>>
>>
>> --
>> MySQL Perl Mailing List
>> For list archives: http://lists.mysql.com/perl
>> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>>
>>
>>
>
>
>
--
Douglas Brantz
Computer consultant
College of Fine & Applied Arts
Appalachian State University
Boone, NC 28608
828-262-6549 office
828-262-6312 - fax
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Question - renaming a file for upload
am 28.09.2007 20:55:40 von brantzdr
Should I use the rename function before the file is uploaded or after? -
I'm not sure if I can change the name of the file before its uploaded -
it seems I might have to change it on the server after the upload?
Modified script below -
Thanks in advance -
Douglas Brantz wrote:
> That didn't seem to work - still uploads file with original name. In
> the example I upload 1 file and form# 405 is added to the beginning of
> the file name for Mysql -
> below the list you see the File that is getting uploaded.
>
> current: 405File1faapage.pdf
> proposed:
> syll1:
> syll2:
> csheet:
> psheet:
>
> File being uploaded: File1faapage.pdf
>
> ------------------------------------------------------------ ---------------------------
>
>
> Greg Meckes wrote:
>> Couldn't you just say?:
>>
>> open (STORAGE, ">$dir/$p$file_name")
>>
>>
>>
>> --- Douglas Brantz wrote:
>>
>>
>>> I need to upload a file to the server and I have that working, but I
>>> want to add the form# to the front of the file:
>>> I can do this to the filename stored in Mysql but how do I change
>>> the name of the file being uploaded to the server?
>>> -
>>> The variable for form number is $p
>>>
>>> I thought I could do this somewhere in this part of the code?
>>>
>>> sub Get_File_Name{
>>> if ($ENV{HTTP_USER_AGENT}=~/win/i){
>>> fileparse_set_fstype("MSDOS");
>>> }
>>> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
>>> fileparse_set_fstype("MacOS");
>>> }
>>> my $full_name = shift;
>>> $full_name = basename($full_name);
>
>>> $full_name = "$p$full_name"; ##>> Added this so I can get the file
>>> name with form# for Mysql
>>> $full_name =~ s!\s!\_!g;
>>> return($full_name);
>>> }
>>> sub Store_File{
>>> my $file_handle = shift;
>>> my $file_name = shift;
>>> my $data;
>>> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
>>> open (STORAGE, ">$dir/$file_name") ## Tried
>>> "..>$dir/$p$file_name"); but it didnt' work.
>>> or die "Error: $!\n";
>>> #if($mime !~ /text/){
>>> binmode ($file_handle);
>>> binmode (STORAGE);
>>> #}
>>> while( read($file_handle, $data, 1024) ){
>>> print STORAGE $data;
>>> }
>>> close STORAGE;
>>> }
>>>
>>> --
>>> Douglas Brantz
>>> Computer consultant
>>> College of Fine & Applied Arts
>>> Appalachian State University
>>> Boone, NC 28608
>>>
>>> 828-262-6549 office
>>> 828-262-6312 - fax
>>>
>>>
>>> --
>>> MySQL Perl Mailing List
>>> For list archives: http://lists.mysql.com/perl
>>> To unsubscribe:
>>> http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>>>
>>>
>>>
>>
>>
>>
>
--
Douglas Brantz
Computer consultant
College of Fine & Applied Arts
Appalachian State University
Boone, NC 28608
828-262-6549 office
828-262-6312 - fax
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Question - renaming a file for upload
am 28.09.2007 21:36:59 von Greg Meckes
You certainly could use rename. You would have to use it after because the file would have to
exist first to be able to rename it.
Greg
--- Douglas Brantz wrote:
> Should I use the rename function before the file is uploaded or after? -
> I'm not sure if I can change the name of the file before its uploaded -
> it seems I might have to change it on the server after the upload?
> Modified script below -
>
> Thanks in advance -
>
>
>
> Douglas Brantz wrote:
> > That didn't seem to work - still uploads file with original name. In
> > the example I upload 1 file and form# 405 is added to the beginning of
> > the file name for Mysql -
> > below the list you see the File that is getting uploaded.
> >
> > current: 405File1faapage.pdf
> > proposed:
> > syll1:
> > syll2:
> > csheet:
> > psheet:
> >
> > File being uploaded: File1faapage.pdf
> >
> > ------------------------------------------------------------ ---------------------------
> >
> >
> > Greg Meckes wrote:
> >> Couldn't you just say?:
> >>
> >> open (STORAGE, ">$dir/$p$file_name")
> >>
> >>
> >>
> >> --- Douglas Brantz wrote:
> >>
> >>
> >>> I need to upload a file to the server and I have that working, but I
> >>> want to add the form# to the front of the file:
> >>> I can do this to the filename stored in Mysql but how do I change
> >>> the name of the file being uploaded to the server?
> >>> -
> >>> The variable for form number is $p
> >>>
> >>> I thought I could do this somewhere in this part of the code?
> >>>
> >>> sub Get_File_Name{
> >>> if ($ENV{HTTP_USER_AGENT}=~/win/i){
> >>> fileparse_set_fstype("MSDOS");
> >>> }
> >>> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
> >>> fileparse_set_fstype("MacOS");
> >>> }
> >>> my $full_name = shift;
> >>> $full_name = basename($full_name);
> >
> >>> $full_name = "$p$full_name"; ##>> Added this so I can get the file
> >>> name with form# for Mysql
> >>> $full_name =~ s!\s!\_!g;
> >>> return($full_name);
> >>> }
> >>> sub Store_File{
> >>> my $file_handle = shift;
> >>> my $file_name = shift;
> >>> my $data;
> >>> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
> >>> open (STORAGE, ">$dir/$file_name") ## Tried
> >>> "..>$dir/$p$file_name"); but it didnt' work.
> >>> or die "Error: $!\n";
> >>> #if($mime !~ /text/){
> >>> binmode ($file_handle);
> >>> binmode (STORAGE);
> >>> #}
> >>> while( read($file_handle, $data, 1024) ){
> >>> print STORAGE $data;
> >>> }
> >>> close STORAGE;
> >>> }
> >>>
> >>> --
> >>> Douglas Brantz
> >>> Computer consultant
> >>> College of Fine & Applied Arts
> >>> Appalachian State University
> >>> Boone, NC 28608
> >>>
> >>> 828-262-6549 office
> >>> 828-262-6312 - fax
> >>>
> >>>
> >>> --
> >>> MySQL Perl Mailing List
> >>> For list archives: http://lists.mysql.com/perl
> >>> To unsubscribe:
> >>> http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >
>
> --
> Douglas Brantz
> Computer consultant
> College of Fine & Applied Arts
> Appalachian State University
> Boone, NC 28608
>
> 828-262-6549 office
> 828-262-6312 - fax
>
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>
>
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Solved - renaming a file for upload
am 28.09.2007 22:24:19 von brantzdr
Got it worked out - thanks - it was in another part of the code -
$CGI::POST_MAX = 1024 * 2;
Get_Names();
sub Get_Names{
my $counter=0;
my $full_name;
my $file_name;
foreach $full_name (@File_Names){
my $rec={};
if ($full_name ne ""){
$file_name = Get_File_Name($full_name);
$file_name = "$p$file_name"; <-------------- Added this line and it
works now
$rec->{file_name} = $file_name;
$rec->{full_name} = $full_name;
$rec->{description} = $Descriptions[$counter];
push @File_Array, $rec;
Store_File($full_name, $file_name);
}
$counter++;
}
}
Greg Meckes wrote:
> You certainly could use rename. You would have to use it after because the file would have to
> exist first to be able to rename it.
>
> Greg
> --- Douglas Brantz wrote:
>
>
>> Should I use the rename function before the file is uploaded or after? -
>> I'm not sure if I can change the name of the file before its uploaded -
>> it seems I might have to change it on the server after the upload?
>> Modified script below -
>>
>> Thanks in advance -
>>
>>
>>
>> Douglas Brantz wrote:
>>
>>> That didn't seem to work - still uploads file with original name. In
>>> the example I upload 1 file and form# 405 is added to the beginning of
>>> the file name for Mysql -
>>> below the list you see the File that is getting uploaded.
>>>
>>> current: 405File1faapage.pdf
>>> proposed:
>>> syll1:
>>> syll2:
>>> csheet:
>>> psheet:
>>>
>>> File being uploaded: File1faapage.pdf
>>>
>>> ------------------------------------------------------------ ---------------------------
>>>
>>>
>>> Greg Meckes wrote:
>>>
>>>> Couldn't you just say?:
>>>>
>>>> open (STORAGE, ">$dir/$p$file_name")
>>>>
>>>>
>>>>
>>>> --- Douglas Brantz wrote:
>>>>
>>>>
>>>>
>>>>> I need to upload a file to the server and I have that working, but I
>>>>> want to add the form# to the front of the file:
>>>>> I can do this to the filename stored in Mysql but how do I change
>>>>> the name of the file being uploaded to the server?
>>>>> -
>>>>> The variable for form number is $p
>>>>>
>>>>> I thought I could do this somewhere in this part of the code?
>>>>>
>>>>> sub Get_File_Name{
>>>>> if ($ENV{HTTP_USER_AGENT}=~/win/i){
>>>>> fileparse_set_fstype("MSDOS");
>>>>> }
>>>>> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
>>>>> fileparse_set_fstype("MacOS");
>>>>> }
>>>>> my $full_name = shift;
>>>>> $full_name = basename($full_name);
>>>>>
>>>>> $full_name = "$p$full_name"; ##>> Added this so I can get the file
>>>>> name with form# for Mysql
>>>>> $full_name =~ s!\s!\_!g;
>>>>> return($full_name);
>>>>> }
>>>>> sub Store_File{
>>>>> my $file_handle = shift;
>>>>> my $file_name = shift;
>>>>> my $data;
>>>>> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
>>>>> open (STORAGE, ">$dir/$file_name") ## Tried
>>>>> "..>$dir/$p$file_name"); but it didnt' work.
>>>>> or die "Error: $!\n";
>>>>> #if($mime !~ /text/){
>>>>> binmode ($file_handle);
>>>>> binmode (STORAGE);
>>>>> #}
>>>>> while( read($file_handle, $data, 1024) ){
>>>>> print STORAGE $data;
>>>>> }
>>>>> close STORAGE;
>>>>> }
>>>>>
>>>>> --
>>>>> Douglas Brantz
>>>>> Computer consultant
>>>>> College of Fine & Applied Arts
>>>>> Appalachian State University
>>>>> Boone, NC 28608
>>>>>
>>>>> 828-262-6549 office
>>>>> 828-262-6312 - fax
>>>>>
>>>>>
>>>>> --
>>>>> MySQL Perl Mailing List
>>>>> For list archives: http://lists.mysql.com/perl
>>>>> To unsubscribe:
>>>>> http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>> --
>> Douglas Brantz
>> Computer consultant
>> College of Fine & Applied Arts
>> Appalachian State University
>> Boone, NC 28608
>>
>> 828-262-6549 office
>> 828-262-6312 - fax
>>
>>
>> --
>> MySQL Perl Mailing List
>> For list archives: http://lists.mysql.com/perl
>> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>>
>>
>>
>
>
>
--
Douglas Brantz
Computer consultant
College of Fine & Applied Arts
Appalachian State University
Boone, NC 28608
828-262-6549 office
828-262-6312 - fax
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
Re: Perl code Solved - renaming a file for upload
am 28.09.2007 23:13:04 von Greg Meckes
Ah, next time include all the code!
--- Douglas Brantz wrote:
> Got it worked out - thanks - it was in another part of the code -
>
> $CGI::POST_MAX = 1024 * 2;
> Get_Names();
> sub Get_Names{
> my $counter=0;
> my $full_name;
> my $file_name;
> foreach $full_name (@File_Names){
> my $rec={};
> if ($full_name ne ""){
> $file_name = Get_File_Name($full_name);
> $file_name = "$p$file_name"; <-------------- Added this line and it
> works now
> $rec->{file_name} = $file_name;
> $rec->{full_name} = $full_name;
> $rec->{description} = $Descriptions[$counter];
> push @File_Array, $rec;
> Store_File($full_name, $file_name);
> }
> $counter++;
> }
> }
>
>
> Greg Meckes wrote:
> > You certainly could use rename. You would have to use it after because the file would have to
> > exist first to be able to rename it.
> >
> > Greg
> > --- Douglas Brantz wrote:
> >
> >
> >> Should I use the rename function before the file is uploaded or after? -
> >> I'm not sure if I can change the name of the file before its uploaded -
> >> it seems I might have to change it on the server after the upload?
> >> Modified script below -
> >>
> >> Thanks in advance -
> >>
> >>
> >>
> >> Douglas Brantz wrote:
> >>
> >>> That didn't seem to work - still uploads file with original name. In
> >>> the example I upload 1 file and form# 405 is added to the beginning of
> >>> the file name for Mysql -
> >>> below the list you see the File that is getting uploaded.
> >>>
> >>> current: 405File1faapage.pdf
> >>> proposed:
> >>> syll1:
> >>> syll2:
> >>> csheet:
> >>> psheet:
> >>>
> >>> File being uploaded: File1faapage.pdf
> >>>
> >>> ------------------------------------------------------------ ---------------------------
> >>>
> >>>
> >>> Greg Meckes wrote:
> >>>
> >>>> Couldn't you just say?:
> >>>>
> >>>> open (STORAGE, ">$dir/$p$file_name")
> >>>>
> >>>>
> >>>>
> >>>> --- Douglas Brantz wrote:
> >>>>
> >>>>
> >>>>
> >>>>> I need to upload a file to the server and I have that working, but I
> >>>>> want to add the form# to the front of the file:
> >>>>> I can do this to the filename stored in Mysql but how do I change
> >>>>> the name of the file being uploaded to the server?
> >>>>> -
> >>>>> The variable for form number is $p
> >>>>>
> >>>>> I thought I could do this somewhere in this part of the code?
> >>>>>
> >>>>> sub Get_File_Name{
> >>>>> if ($ENV{HTTP_USER_AGENT}=~/win/i){
> >>>>> fileparse_set_fstype("MSDOS");
> >>>>> }
> >>>>> elsif($ENV{HTTP_USER_AGENT}=~/mac/i){
> >>>>> fileparse_set_fstype("MacOS");
> >>>>> }
> >>>>> my $full_name = shift;
> >>>>> $full_name = basename($full_name);
> >>>>>
> >>>>> $full_name = "$p$full_name"; ##>> Added this so I can get the file
> >>>>> name with form# for Mysql
> >>>>> $full_name =~ s!\s!\_!g;
> >>>>> return($full_name);
> >>>>> }
> >>>>> sub Store_File{
> >>>>> my $file_handle = shift;
> >>>>> my $file_name = shift;
> >>>>> my $data;
> >>>>> #my $mime = uploadInfo($File_handle)->{'Content-Type'};
> >>>>> open (STORAGE, ">$dir/$file_name") ## Tried
> >>>>> "..>$dir/$p$file_name"); but it didnt' work.
> >>>>> or die "Error: $!\n";
> >>>>> #if($mime !~ /text/){
> >>>>> binmode ($file_handle);
> >>>>> binmode (STORAGE);
> >>>>> #}
> >>>>> while( read($file_handle, $data, 1024) ){
> >>>>> print STORAGE $data;
> >>>>> }
> >>>>> close STORAGE;
> >>>>> }
> >>>>>
> >>>>> --
> >>>>> Douglas Brantz
> >>>>> Computer consultant
> >>>>> College of Fine & Applied Arts
> >>>>> Appalachian State University
> >>>>> Boone, NC 28608
> >>>>>
> >>>>> 828-262-6549 office
> >>>>> 828-262-6312 - fax
> >>>>>
> >>>>>
> >>>>> --
> >>>>> MySQL Perl Mailing List
> >>>>> For list archives: http://lists.mysql.com/perl
> >>>>> To unsubscribe:
> >>>>> http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >> --
> >> Douglas Brantz
> >> Computer consultant
> >> College of Fine & Applied Arts
> >> Appalachian State University
> >> Boone, NC 28608
> >>
> >> 828-262-6549 office
> >> 828-262-6312 - fax
> >>
> >>
> >> --
> >> MySQL Perl Mailing List
> >> For list archives: http://lists.mysql.com/perl
> >> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
> >>
> >>
> >>
> >
> >
> >
>
> --
> Douglas Brantz
> Computer consultant
> College of Fine & Applied Arts
> Appalachian State University
> Boone, NC 28608
>
> 828-262-6549 office
> 828-262-6312 - fax
>
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=gregmeckes@yahoo.com
>
>
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org