Results 1 to 13 of 13

Thread: CGI - Create File

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    CGI - Create File

    I'm creating a file in CGI (Perl), but after it's created via the script, I can't replace it or chmod it.

    What's the correct way to create a file in perl?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    okay, I'm using this code to create the file:

    Code:
        open(NEWFILE,">".$filename);
        print NEWFILE $text;
        close NEWFILE;
    Should I be using something else?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    Hey, here's what you want:

    Code:
    open(FILE, ">>$file") or die "couldn't open file: $!";
    print FILE "Blah Blah balh\n";
    close(FILE);
    if you need more help, my AIM sn is mexicanok.
    -Jose

  4. #4
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    What you're actuallin doing is erasing the old content of the file and adding $text, you want to use >> which appends to the file. I hope that helps, don't forget to IM me if you need more help.
    -Jose

  5. #5
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    Ok, i'm sorry.. i missunderstood your question......
    You can create a file like you did. but add the "or die" part so you can identify the error. to chmod it just use the chmod function.
    -Jose

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I think you're still misunderstanding me.

    When I create the file, and then say I try to replace it by uploading a different copy of it, it won't let me.

    Why is this?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    I still don't know what you mean. I'm just gonna post some code to see if it helps.
    Code:
    #Create a file, if $file already excists, it erases
    #whatever it had, and save $content.
    open(FILE,">$file") or die "Coundn't open $file: $!";
    print FILE $content;
    close(FILE);
    
    #append to the file
    open(FILE,">>$file") or die "Couldn't open $file: $!";
    pring FILE $content;
    close(FILE);
    I hope that helped.
    -Jose

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The first example is what I am using.

    Say I create a file called file1.txt with that code. When I try to upload file1.txt (and replace the one created) it won't let me. I can, however, delete it and then upload it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    Show me some more code (replacing the file) and why doesn't it let you?
    -Jose

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    There is no code to upload the file, it's uploaded by FTP (sorry I neglected that)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Is there anyway you could help me with my other CGI problem (with cookies) posted in this forum?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    You running Apache on *nix? The Perl script might be run as a different user than what you're logging on as - a "nobody" account, or an "apache" account. I believe the "chown" command can fix this, but its been a while since I've seriously used *nix.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  13. #13
    New Member
    Join Date
    Feb 2002
    Location
    Indiana
    Posts
    12
    My email address is [email protected], Ask anything you want, i'll always reply, I just don't check this too much.
    -Jose

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width