PHP fopen() not creating file.

Discussion in 'Web Design and Development' started by iTim314, Feb 4, 2008.

  1. iTim314 macrumors 6502

    Joined:
    Jun 5, 2005
    Location:
    U.S.
    #1
    I'm trying to setup a PHP script to create a file if it does not already exist.

    Example:
    PHP:
    $ourFileName "testFile.txt";
    $ourFileHandle fopen($ourFileName'w') or die("can't open file");
    fclose($ourFileHandle);
    That's the first, and simplest one I've tried. I've tried multiple scripts, but none are creating the file I want.

    I'm developing this site under Mac OS X, not OS X server.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Most likely a permissions issue. Looks like you code this code at, http://www.tizag.com/phpT/filecreate.php

    If you look at the bottom of the page you'll find,

     
  3. iTim314 thread starter macrumors 6502

    Joined:
    Jun 5, 2005
    Location:
    U.S.
    #3
    Yeah I saw that, unfortunately I'm at a loss as to what file(s) needs to be set to 777. :confused:

    I tried the .php file, of course with no results. PHP is more of a hobby for me so I'm not that fluent with it.


    Also answer me this if you will: I'm developing this site on top of Mac OS X, and it's being hosted on a Windows machine (reluctantly). Will I have to chmod the same file(s) to 777 in order for the same scripts to work?
     
  4. pointycollars macrumors regular

    Joined:
    May 15, 2007
    Location:
    Cincinnati
    #4
    Make sure the folder you are trying to create files in has the right permissions (allow writes and reads). I've run into this issue many times, and that seems to solve it each time.
     
  5. iTim314 thread starter macrumors 6502

    Joined:
    Jun 5, 2005
    Location:
    U.S.
    #5
    Thanks for everyone's help!

    Come to find, I had to go all the way back to the /Library/WebServer/Documents/ folder, CMD+I and manually change the owner to myself. :confused:


    Oh well. It's working now, so thanks for any advice that may have helped! :D
     
  6. fettuccini macrumors newbie

    Joined:
    May 24, 2008
    #6
    I'm developing with PHP locally and was having the exact same issues with fopen()... turns out it was just a permissions problem. I'm glad I found this thread. :)
     

Share This Page