File- ?create one if does not exist

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Andy128
    Major General

    • Dec 2005
    • 2317

    File- ?create one if does not exist

    I have a form and a script that processes that form, and writes the data to a flat file. However- setting the file mode to "a" or "a+" does not allow the file to be created if it is not present. At least when I attempt it. Here is the script portion dealing with the file open;

    if(is_writable('file1.txt'))
    {
    $fp = fopen('file1.txt','a');
    So- is there something else I need to do here or is the ability to create a file like this stopped by settings on the server?

    Andy
    PHP- is a blast!
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: File- ?create one if does not exist

    if (!$nd_handle = fopen($nd_file_name, 'a+')) {
    die("Cannot open file ($nd_file_name)");
    exit;
    }
    if (fwrite($nd_handle, $nd_values) === FALSE) {
    die("Cannot write to file ($nd_filename)");
    exit;
    }
    fclose($nd_handle);

    Andy, this code will create a file, with the name contained in $nd_filename, and will place in it the values contained in $nd_values. The "+a" string mode is equivalent to the simple "a" you are using, only that it opens the file in both writing and reading mode. Try it instead of the simple "a"
    This is the code used by ABVFP in the ndadmin1.php file, and it creates the file alright, and, ofcourse, it doesn't exist before you run ndadmin.php. From what i know, it has worked on all VH servers, so there should be no issue.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • Andy128
      Major General

      • Dec 2005
      • 2317

      #3
      Re: File- ?create one if does not exist

      Thanks Navaldesign- I shall give it a go!

      Andy
      PHP- is a blast!

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: File- ?create one if does not exist

        Just a question: why not go the DB way ? (I HATE flat files, but, ofcourse, this is just my personal opinion)
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • Andy128
          Major General

          • Dec 2005
          • 2317

          #5
          Re: File- ?create one if does not exist

          I am just learning. I figure If I can understand flat files- when I graduate in my learning to DB's it will be a snap. I am having fun along the way.

          Oh- and I figured (with a little help) out my previous problem. I tested to see if it was writeable first. If it does not exist it would not be writeable and thus the error with the rest of the script. So back to the drawing board.

          Good talking with ya Naval! Have great day!

          Andy
          PHP- is a blast!

          Comment

          Working...
          X