PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
hey thanks hansford - you´re exactly right, since the file doesn´t exist it throws that warning. however, the idea is to create the file. if you look at the php manual which you linked it says:
w : Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
the key sentence being the last one - "if the file doesn´t exist, attempt to create it".
Also in my search i´ve seen several other tutorials that, if i understood them correctly, used fopen in this way to create a file... (though i can´t get them to work either) - maybe i missing something.
if not fopen, is there some other way to write php code which creates and writes to a new file?
Your code works fine except the for the
!chmod($path, 0744)) part. This is where I was getting an error. I removed it-did a check and the file was written.
----------------------------
<?php
brookisme, the problem is not with the fopen, it is with the chmod. You cannot chmod a file that doesn't exist. As hansford said, the code works if he removes the chmod. Also, your error says that the issue is in line 4 which is your chmod line. It looks like you are trying to use chmod to find out if a file exists. This is a bad idea. Use "if (file_exists("filename.ext")) {".