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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: xmeltrut at gmail dot com
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC