SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cant create file

    I have this problem. i use mkdir() to create a folder. after that, i use touch() to create a file but the file somehow cant be created. Why is it like this?
    The folder has chmod 777, why cant i use touch to create a file in this
    folder? how can i solve this problem in order to create the file?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,457
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Hi firestarapple, welcome to the forums (posting-wise).

    I have never used touch(), but my error reporting plugin uses
    PHP Code:
    chmod($main_dir0705);
    exec("chmod 604 " $main_dir '/*.log'); 
    *NOTE that chmod() uses octal

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any other method besides touch() to create a blank file?

  4. #4
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,457
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I have never used touch(), and thought it was to modify the access time. But after looking at the documentation
    Attempts to set the access and modification times of the file named in the filename parameter to the value given in time . Note that the access time is always modified, regardless of the number of parameters.

    If the file does not exist, it will be created.
    I see that it can create files.

    I have used fopen() before. And it too can create files.
    '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.
    'w+' Open for reading and writing; 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.
    'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
    'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
    So you could try fopen() then file_exists() to see if it was created and then fclose() without writing anything to it I suppose.


Bookmarks

Posting Permissions

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