PDA

View Full Version : PHP fopen() not creating file.




ChexBoss32890
Feb 4, 2008, 06:26 PM
I'm trying to setup a PHP script to create a file if it does not already exist.

Example:
$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.



angelwatt
Feb 4, 2008, 06:39 PM
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.

ChexBoss32890
Feb 4, 2008, 06:45 PM
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?

pointycollars
Feb 4, 2008, 06:49 PM
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.

ChexBoss32890
Feb 4, 2008, 06:55 PM
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

fettuccini
May 24, 2008, 12:30 PM
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. :)