php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63456 Option for fopen to create directories
Submitted: 2012-11-07 14:49 UTC Modified: 2012-11-08 02:22 UTC
From: xmeltrut at gmail dot com Assigned:
Status: Wont fix Package: Filesystem function related
PHP Version: 5.4.8 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-11-07 14:49 UTC] xmeltrut at gmail dot com
Description:
------------
Currently, fopen allows you to create new files, but not in directories that don't 
exist - for example, if you want to write to /tmp/logs/something.log, you have to 
check that /tmp/logs exists every time, before running your fopen.

It would be convenient if you could pass a flag to fopen to tell it to recursively 
create any missing directories in the path, in order to open the file.

Test script:
---------------
fopen('/tmp/logs/test.log', 'w'); // fails if logs doesn't exist

mkdir('/tmp/logs');
fopen('/tmp/logs/test.log', 'w'); // fails if logs does exist


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-08 02:22 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2012-11-08 02:22 UTC] aharvey@php.net
Conceptually, fopen() is really just a wrapper for the C fopen() function, which behaves the same way. Since mkdir() does have a recursive option, I don't think there's much value in adding another variation to how fopen() behaves — there are enough already.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Feb 16 20:01:24 2019 UTC