From: kemal at thelimelight dot nl
Operating system: Windows NT 4.0 SP6
PHP version: 4.2.3
PHP Bug Type: Filesystem function related
Bug description: Permission denied for unlink() , copy(), rename(),
move_uploaded_file() FAT32
(I have tested this with PHP 4.2.3 and PHP 4.3.1 running as a CGI process
under IIS 4 on NT4-SP6 server with FAT file system)
The situation:
After receiving a submission from an HTML form which includes an uploaded
file, I need to move the uploaded file from its temporary place to its
final place.
The problem:
Whenever the target location already have a file with the same name, the
PHP command would fail with either 'unable to create' and/or 'permission
denied' type of warnings. It does not matter whether I use one simple
move_uploaded_file() function or a combination of unlink(), copy() and
rename() functions. It even fails when I use the system() or exec()
function. Please remember that the existing file is not marked
'read-only' and the user account (I_USR) does have write capability on
the intended directory.
I have already tried using double backward slash as path separator
(instead of forward slash), using full path to root of drive (instead of
relative), giving I_USR account administrator priviledges, sharing the
target directory, moving temp directory to the same drive as the target
directory, disabling warning message generation (using the @ prefix),
trying to unlink or move the files using multiple strategy one after the
other, etc.
Interesting behaviour:
The PHP commands would not always fail. Once in a while, it would
succeed. Espescially after the script has died. (Seems to react
differently when there is a time lapse)
**** SAMPLE SCRIPT FOR BUG TESTING:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>upload test</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="Fri, 1 January 1999 12:00:00 EST">
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="65536">
<?php
$vname = 'myfile';
$target = './my_uploaded_image.jpg';
$name = $_FILES[$vname]['name'];
$type = $_FILES[$vname]['type'];
$size = $_FILES[$vname]['size'];
$temp = $_FILES[$vname]['tmp_name'];
$err = $_FILES[$vname]['error'];
if (is_uploaded_file($temp)) {
if (!move_uploaded_file($temp, $target)) {
echo "<strong>Error:</strong> Unable to accept file $name<br>";
}
}
if (is_file($target)) {
echo sprintf('<img src="%s" border="0">', $target);
} else {
echo "(no image file)";
}
?><br>
Specify here an jpeg image file to be uploaded:<br>
<input type="file" name="<?php echo $vname; ?>"><br>
<input type="Submit" value="Upload">
</form>
</body>
</html>
**** WORK AROUND THAT SEEMS TO WORK:
change the simple move_uploaded_file() invocation to:
$n = 0;
while ([EMAIL PROTECTED]($temp, $target) and $n<100) {
clearstatcache();
sleep(1);
$n++;
}
--
Edit bug report at http://bugs.php.net/?id=22488&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22488&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22488&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22488&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22488&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22488&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22488&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22488&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22488&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22488&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22488&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22488&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22488&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22488&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22488&r=gnused