Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iTim314

macrumors 6502
Original poster
Jun 5, 2005
337
6
U.S.
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.
 
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,

If you are trying to get this program to run and you are having errors, you might want to check that you have granted your PHP file access to write information to the hard drive. Setting permissions is most often done with the use of an FTP program to execute a command called CHMOD. Use CHMOD to allow the PHP file to write to disk, thus allowing it to create a file.
 
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?
 
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.
 
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
 
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.