php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35380 Provide information about the current temporary directory
Submitted: 2005-11-25 04:28 UTC Modified: 2006-05-06 10:02 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: daniel dot gorski at develnet dot org Assigned: hholzgra (profile)
Status: Closed Package: Feature/Change Request
PHP Version: Any OS: Any
Private report: No CVE-ID: None
 [2005-11-25 04:28 UTC] daniel dot gorski at develnet dot org
Description:
------------
It is not possible to programatically get the information about the directory used by PHP where to store temporary files - if the session save path is not set in the php.ini (default). There is no chance to get an unusal path (unlike /tmp/) for temporary directory on OSes like Windows.

Creating a _single_ temporary file by e.g. tmpfile() doesn't solve the problem if an additional temporary structure, e.g. for caching purposes, needs to be created beneath the temp directory and an userland method requires the path on which it can work on.

If running on Windows the location of the temporary directory might differ. The code - or the - recognition of it is already solved in PHP:

http://lxr.php.net/source/php-src/main/php_open_temporary_file.c#161

But there is no way to get this information whilst a script is running.


Reproduce code:
---------------
-none-

Expected result:
----------------
A constant or function that reflects/returns the status of PHPs internal php_tmpdir()/php_get_temporary_directory() for the current running script.

Actual result:
--------------
not available, but thank you for fixing in advance.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-01 23:29 UTC] daniel dot gorski at develnet dot org
Any opinions?

regards dtg
 [2006-01-10 05:38 UTC] daniel dot gorski at develnet dot org
*ping* ?!
 [2006-03-07 00:28 UTC] daniel dot gorski at develnet dot org
I found additionally found <http://bugs.php.net/bug.php?id=24087> from 2 1/2 years ago, that refers to the same problem.

Guys, it is not that problematic to provide that temporary file information, why don't you do it? It's the simplest change you could ever do with big impact.

There is no issue that is against that problem, but is it important to know the current temporary directory for software that should work on WinXX.

PLEASE introduce a function or a CONSTANT, that reflects, what PHP internally knows! Thank you,
 [2006-03-22 04:52 UTC] daniel dot gorski at develnet dot org
Is there anybody out there, who feels responsible for that issue?

regards dtg
 [2006-05-03 22:45 UTC] hholzgra@php.net
the following patch adds a PHP function php_get_tmpdir()
that simply exposes the C API function php_get_temporary_directory() 
to PHP userland (and i took the freedom to shorten the name there):


Index: ext/standard/basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.769
diff -u -r1.769 basic_functions.c
--- ext/standard/basic_functions.c  3 Apr 2006 13:46:35 -0000 1.769
+++ ext/standard/basic_functions.c  3 May 2006 22:42:59 -0000
@@ -846,6 +846,8 @@
  PHP_FE(output_add_rewrite_var,                      NULL)
  PHP_FE(output_reset_rewrite_vars,                   NULL)
 
+ PHP_FE(php_get_tmpdir,            NULL)
+
  {NULL, NULL, NULL}
 };
 
Index: ext/standard/file.c
===================================================================
RCS file: /repository/php-src/ext/standard/file.c,v
retrieving revision 1.440
diff -u -r1.440 file.c
--- ext/standard/file.c 2 May 2006 18:23:32 -0000 1.440
+++ ext/standard/file.c 3 May 2006 22:43:00 -0000
@@ -2555,6 +2555,14 @@
 /* }}} */
 #endif
 
+/* {{{ proto string php_get_tmpdir()
+   Get directory path for temporary files */
+PHP_FUNCTION(php_get_tmpdir)
+{
+ RETURN_STRING((char *)php_get_temporary_directory(), 1);
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
Index: ext/standard/file.h
===================================================================
RCS file: /repository/php-src/ext/standard/file.h,v
retrieving revision 1.97
diff -u -r1.97 file.h
--- ext/standard/file.h 13 Jan 2006 04:10:32 -0000  1.97
+++ ext/standard/file.h 3 May 2006 22:43:00 -0000
@@ -66,6 +66,7 @@
 #endif
 PHP_NAMED_FUNCTION(php_if_ftruncate);
 PHP_NAMED_FUNCTION(php_if_fstat);
+PHP_FUNCTION(php_get_tmpdir);
 
 PHP_MINIT_FUNCTION(user_streams);
 

 [2006-05-03 22:53 UTC] daniel dot gorski at develnet dot org
Thank you, Hartmut.

Is there any chance to commit this patch to the 5.1 branch?

regards dtg
 [2006-05-06 10:02 UTC] hholzgra@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 23:01:30 2024 UTC