+ Reply to Thread
Results 1 to 5 of 5

Thread: File- ?create one if does not exist
      
   

  1. #1
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default 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!

  2. #2
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default 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!


  3. #3
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: File- ?create one if does not exist

    Thanks Navaldesign- I shall give it a go!

    Andy
    PHP- is a blast!

  4. #4
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default 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!


  5. #5
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default 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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49