ID:               44222
 User updated by:  c dot d dot brengel at att dot net
 Reported By:      c dot d dot brengel at att dot net
 Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Windows XP
 PHP Version:      5.2.5
 New Comment:

Thank You.  I just needed to know if was a problem with my system, PHP
or Windows.  Thank You for confirming it is a Windows problem.

I have used another work around so I do not need to use "tempnam".

It would be a good idea to update the PHP documentation to let others
know of this behavior on WIndows.  

Keep up the good work


Previous Comments:
------------------------------------------------------------------------

[2008-03-06 23:08:23] a dot u dot savchuk at gmail dot com

As i understand it is not bug but described behavior of windows
GetTempFileName() function.
So it is not possible to fix that (in easy manner).

>From MSDN http://msdn2.microsoft.com/en-us/library/aa364991.aspx :
...
lpPrefixString
    The null-terminated prefix string. The function uses up to the
first three characters of this string as the prefix of the file name.
...

Other possible solution is to create own version of GetTempFileName()
under Windows
but i think  htta more simple and correct solution is to describe it in
docu as Windows-specific issue...

Also there are some possible problems can occur with this function
under Windows:
1. if temp directory path length more than MAXPATH-14 :
...
lpPathName
    The directory path for the file name. Applications typically
specify a period (.) for the current directory or the result of the
GetTempPath function. The string cannot be longer than MAX_PATH–14
characters or GetTempFileName will fail. If this parameter is NULL, the
function fails.
...

so if templ directory will have (MAXPATHLEN-13) symbols
then PHP check of length will successfully pass
but GetTempFileName() will fail.

There is patch for fix this problem:

$ diff -upd /home/sawoy/source/php-5.2.5/main/php_open_temporary_file.c
./main/php_open_temporary_file.c
--- /home/sawoy/source/php-5.2.5/main/php_open_temporary_file.c
2007-08-10 03:13:15.000000000 -0700
+++ ./main/php_open_temporary_file.c    2008-03-06 15:00:22.000000000
-0800
@@ -131,7 +131,11 @@ static int php_do_open_temporary_file(co
                trailing_slash = "/";
        }

+#ifdef PHP_WIN32
+       if (spprintf(&opened_path, 0, "%s", new_state.cwd) >
(MAXPATHLEN - 14)) {
+#else
        if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", new_state.cwd,
trailing_slash, pfx) >= MAXPATHLEN) {
+#endif
                efree(opened_path);
                free(new_state.cwd);
                return -1;


2. due algo of GetTempFileName() it will be not possible to create more
than 65535 temporary files in on temp directory. 
On box where i tested it it can create only 65324 files and on next
script hangs...

Also for info: time of creation 65xxx-th file in one temp directory is
encreased in ~10-15 times :)

------------------------------------------------------------------------

[2008-02-22 21:41:45] c dot d dot brengel at att dot net

Description:
------------
It appears that when using "tempnam" the $prefix parameter only accepts
3 characters.  I used tempnam(getcwd(),'ADR'.date(Y.m.d).'_')
and the resulting file name ended up as "ADRBA.tmp" not the 
"ADR2008222_BA.tmp" that it should have given.

I then tried tempnam(getcwd(), 'ADR123') and stil got only ADRXX.tmp.

Not sure but would appreciate it if you could determine if this is in
fact correct behavior.



Reproduce code:
---------------
<?php
echo getcwd() . "\n\r";
chdir('tmp');
echo getcwd() . "\n\r";
$file=tempnam(getcwd(),'ADR'.date(Y.m.d).'_');
echo "$file";
?>

Expected result:
----------------
C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADR2008222_C2.tmp 


Actual result:
--------------
C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADRC2.tmp 



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44222&edit=1

Reply via email to