Hi there, I'd greatly appreciate any insights into the following problem: I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: 4.3.11). In PHP, the user uploads a file, which is then processed and the contents are inserted into a new file, created in PHP, onto the server. This bit works fine, the new file created by PHP is correctly stored. Later, once the user confirms the upload and PHP inserts the contents of the file into the DB, the code tries to remove the file created in PHP moments earlier, via the unlink() function. What I see on screen is the following: Permission denied I have made sure that the permissions for the Internet account that created (and is trying to delete) the file have full permissions over this particular folder and the files within it. But the user must have permission anyway, because they are able to create this file in the first place. I've looked at the permissions for the file in PHP, which read: 0666. So everthing *appears* ok to me; I can't see where the permission issue is coming from. Anyone got any ideas? TIA, Lorenzo.
<lorenzogordon@hotmail.com> wrote in message news:1143022232.809686.208670@i39g2000cwa.googlegroups.com... > Hi there, > > I'd greatly appreciate any insights into the following problem: > > I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: > 4.3.11). > > In PHP, the user uploads a file, which is then processed and the > contents are inserted into a new file, created in PHP, onto the server. > > This bit works fine, the new file created by PHP is correctly stored. > > Later, once the user confirms the upload and PHP inserts the contents > of the file into the DB, the code tries to remove the file created in > PHP moments earlier, via the unlink() function. > > What I see on screen is the following: Permission denied > > I have made sure that the permissions for the Internet account that > created (and is trying to delete) the file have full permissions over > this particular folder and the files within it. But the user must have > permission anyway, because they are able to create this file in the > first place. > > I've looked at the permissions for the file in PHP, which read: 0666. > So everthing *appears* ok to me; I can't see where the permission issue > is coming from. > > Anyone got any ideas? This is just a wild guess, but if you open the file with fopen, for example, and then leave it open without fclose, and while the file is open you try to unlink it, the file is concidered unremovable because it's in use by php. Could something like this be the reason? -- "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirvi� spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
Good question. Here's the function I'm using to write the file, the function is returning true, which indicates that the file is being closed properly. (I've used this function to perform the identical same task on a Unix server, where it works fine, it's just on IIS I'm having this problem): function WriteFile($FileName, $TextString) { $File = fopen($FileName, "w"); if ($File == false) { return false; } else { if (flock($File, LOCK_EX)) { fwrite($File, $TextString); flock($File, LOCK_UN); fclose($File); return true; } else { return false; } } } Any other ides? lorenzo.
I read here (http://groups.google.co.uk/group/mailing.www.php-dev/browse_frm/thread/f4bc2a7985cc4e/46c596d1917561f0?lnk=st&q=php+windows+permission+denied+unlink&rnum=8&hl=en#46c596d1917561f0) about an issue on a Windows server that caused the same problem I'm experiencing, because the file had recently been used by IIS. I tried add sleep(20), but that made no difference. If anyone has any suggestions, please post them here. Cheers, Lorenzo.
I read here (http://groups.google.co.uk/group/mailing.www.php-dev/browse_frm/thread/f4bc2a7985cc4e/46c596d1917561f0?lnk=st&q=php+windows+permission+denied+unlink&rnum=8&hl=en#46c596d1917561f0) about an issue on a Windows server that caused the same problem I'm experiencing, because the file had recently been used by IIS. I tried add sleep(20), but that made no difference. If anyone has any suggestions, please post them here. Cheers, Lorenzo.
lorenzogordon@hotmail.com wrote: > Hi there, > > I'd greatly appreciate any insights into the following problem: > > I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: > 4.3.11). > > In PHP, the user uploads a file, which is then processed and the > contents are inserted into a new file, created in PHP, onto the server. > > This bit works fine, the new file created by PHP is correctly stored. > > Later, once the user confirms the upload and PHP inserts the contents > of the file into the DB, the code tries to remove the file created in > PHP moments earlier, via the unlink() function. > > What I see on screen is the following: Permission denied > > I have made sure that the permissions for the Internet account that > created (and is trying to delete) the file have full permissions over > this particular folder and the files within it. But the user must have > permission anyway, because they are able to create this file in the > first place. > > I've looked at the permissions for the file in PHP, which read: 0666. > So everthing *appears* ok to me; I can't see where the permission issue > is coming from. > > Anyone got any ideas? > > TIA, > > Lorenzo. Is the file saved in a web-accessible folder? IIS could be indexing the new file.
Sorry, I'm not so hot on IIS, can you explain what IIS does if it's indexing the file? The folder is outside the web root, so no it's not web-accessible. What are the implications of this? Thanks, Lorenzo.
> I read here > (http://groups.google.co.uk/group/mailing.www.php-dev/browse_frm/thread/f4bc2a7985cc4e/46c596d1917561f0?lnk=st&q=php+windows+permission+denied+unlink&rnum=8&hl=en#46c596d1917561f0) > about an issue on a Windows server that caused the same problem I'm > experiencing, because the file had recently been used by IIS. > I tried add sleep(20), but that made no difference. > > If anyone has any suggestions, please post them here. This is a known problem with IIS. You can't unlink/delete a file that has been created during the lifetime of an IIS managed session - whether that file was created using PHP, vbscript or whatever. Your workaround is either to use throwaway files, that will all be unlinked when the server is next restarted; or use some other persistence method such as a database. Seek further info from an appropriate comp.database.* group. --- Steve
Thanks for the info, Steve. What counts as a managed session; until IIS is re-started, or until the connection with that particular client is terminated? (What I'm wondering is whetehr I can clean-up the files a day later, once the user has logged off, even if IIS has not been re-started?) Cheers, Lorenzo.
> What counts as a managed session; until IIS is re-started, or until the > connection with that particular client is terminated? > (What I'm wondering is whetehr I can clean-up the files a day later, > once the user has logged off, even if IIS has not been re-started?) >From memory you can issue the delete requests, but the files are only removed when IIS is stopped. --- Steve
Thanks Steve. I just ran a little test. I uploaded a file, then an hour later (with the same browser window) I ran the unlink code and it worked. I guess IIS needs mroe than 20 seconds (the length I set the sleep function for) to give-up the file. Lorenzo.