473,378 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

PHP/IIS: File Read/Write OK, File Unlink Denied

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.

Mar 22 '06 #1
10 7538
<lo***********@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.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
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 22 '06 #2
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.

Mar 22 '06 #3
I read here
(http://groups.google.co.uk/group/mai...c596d1917561f0)
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.

Mar 22 '06 #4
I read here
(http://groups.google.co.uk/group/mai...c596d1917561f0)
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.

Mar 22 '06 #5
lo***********@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.

Mar 23 '06 #6
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.

Mar 23 '06 #7
I read here
(http://groups.google.co.uk/group/mai...c596d1917561f0)
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

Mar 23 '06 #8
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.

Mar 23 '06 #9
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

Mar 23 '06 #10
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.

Mar 23 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really...
1
by: David Arden Stevensonn | last post by:
Say I have an XML file on my website that gets read alot (by a c# aspx page) but written to occasionally (also by the same c# aspx page) . Its a simple caching situation based on time. Example: If...
2
by: Smoothy | last post by:
Hi all, Can someone help me with the following issue? I want to read/write from/to a particular position (line/character) of a text file. How can I do this? In other words, how can I tell to...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
1
by: Nadja Schmitt | last post by:
Hi! Is it possible to read/write a *.resx-file? The problem: I'd like to add some more columns to my resource-file, than read the data out of the file and write the data in this file. I...
1
by: gce | last post by:
Hi, As a newbie (old vb6 programmer) I like to know how to read/write/lock a file using asp.net ? Best regards, Gert
0
by: Frederic Rentsch | last post by:
Hi all, Working with read and write operations on a file I stumbled on a complication when writes fail following a read to the end. 30L 'abcdefg' Traceback (most recent call last): File...
4
by: Bruno | last post by:
Hi! I have big .txt file which i want to read, process and write to another .txt file. I have done script for that, but im having problem with croatian characters (Š,Đ,Ž,Č,Ć). How can I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.