View previous topic :: View next topic |
Author |
Message |
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 5:00 pm Post subject: mkdir() file in use or write protected error |
|
|
Hi all,
I've made a script that uploads a file by creating a dir and writes a file to it.
Code: |
mkdir("uploads/SessionID/filename");
|
I can't seem to manually delete the file or dir via windows explorer. I get a file in use or write protected error.
Is this a php or windows issue?
Suggestions? _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 12, 2005 5:44 pm Post subject: |
|
|
PHP might still be running. Stop PHP in task manager and try it again. PHP may have the folder/files open so it protects it. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Wed Oct 12, 2005 5:44 pm Post subject: |
|
|
Does the problem persist after a reboot and before restarting Abyss? (ie does the file become deletable?)
Sounds like you're not closing the file correctly, maybe. _________________
"Invent an idiot proof webserver and they'll invent a better idiot..." |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 5:52 pm Post subject: |
|
|
I haven't tried rebooting abyss because it seems the 'problem' occured only after I made this script.
I am able to unlink() each of the files, and then rmdir() via script. (kind of a pain for just a test script)
Almost like there is a owner/chmod issue, even though there's no need for chmod.
Shtill Shtuck on this one. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Wed Oct 12, 2005 6:02 pm Post subject: |
|
|
Windows 98 has no concept of owners at all.
Quote: | I haven't tried rebooting abyss because it seems the 'problem' occured only after I made this script. |
That was exactly the point - if your script is not closing files correctly, they will be undeleteable by other Windows processes. If you include the rmdir in the same script, the same PHP process has control of the file, so I'd assume some kind of sanity check takes place and forces the file closed before deletion.
The suggestion of rebooting would mean all file handles were closed, allowing you to test whether the file can be deleted normally. If it can, it's a problem with your coding / PHP. It's not a problem with Abyss as Abyss doesn't touch the file at all - it will all be handled by the PHP interpreter. _________________
"Invent an idiot proof webserver and they'll invent a better idiot..." |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 7:01 pm Post subject: [Solved] |
|
|
You hit it right on the head Anonymoose. It just wasn't making sense to me.
(almost feel bad I posted it in here) I haven't rebooted that thing in months.
A reboot, and away we go .... _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 9:49 pm Post subject: |
|
|
Back to the same thing again. I can rmdir(), but then have to manuall remove via explorer.
Must be something with my OS? _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 12, 2005 9:56 pm Post subject: |
|
|
Windows 98 isnt exactly the best operating system to use on a server. I much prefer XP myself. You should try it out and see if it works better.
According to TRUSTpunk Win2k3 is extreamly good for servers. He says it executes PHP faster too because there is no crap running in the background like on other Windows OS's. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 10:00 pm Post subject: |
|
|
Running XP Pro here. This just doesnt make any sense. Does this code look poor to you?
Code: | /**********************
* remove dir
**********************/
if(isset($_POST['remove'])){
// 1st remove each file
$handle = opendir($target_path);
while (false !== ($file = readdir($handle))){
unlink($target_path . "/" . $file);
}
closedir($handle);
// remove the dir
if(rmdir($target_path)){
print("YAY<br />");
} else {
print("BOO<br />");
}
//print results
print("files and dir removed<br />");
} |
_________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 12, 2005 10:03 pm Post subject: |
|
|
The code looks fine to me. It says in your sig you are running 98FE, which is why I assumed you did. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 10:06 pm Post subject: |
|
|
ACK! I was wondering where you guys were getting that from! Abyss is so solid I haven't been back here for support in a loooong time! Will fixy ;-) _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 12, 2005 10:21 pm Post subject: |
|
|
Yeh, I have no problems with Abyss. Thats why I run it ;-) _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 10:26 pm Post subject: [solved] |
|
|
OK I solved this. I don't understand it completely but this is what I did to get it to work. I added is_dir():
Code: | /**********************
* remove dir
**********************/
if(isset($_POST['remove'])){
// 1st remove each file
$handle = opendir($target_path);
while (false !== ($file = readdir($handle))){
unlink($target_path . "/" . $file);
}
closedir($handle);
// remove the dir
if(is_dir($target_path)){
if(rmdir($target_path)){
print("YAY<br />");
} else {
print("BOO<br />");
}
}
//print results
print("files and dir removed<br />");
} | Must be a windows thing? _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Oct 12, 2005 10:30 pm Post subject: |
|
|
Hmm weird. Must be good ol' windows! _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Wed Oct 12, 2005 10:37 pm Post subject: |
|
|
Actually I think it's php. Here's why I think that:http://us3.php.net/manual/en/language.types.php
rmdir($path) <-- php sees $path as a string
if(is_dir($path)){ rmdir($path); } <-- you are telling php that $path is a dir
Only guessing. I never thought much about it I guess. php does so much cool stuff automatically. That maybe I got lazy ;-) _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Fri Oct 28, 2005 3:29 pm Post subject: move_uploaded_file() works, but access denied? |
|
|
Ok got the rmdir() thing working. NOW I can't open the uploaded file:
Code: | <?php
// session id var
$sessid = session_id();
// define path to sessID folder in dir
$target_path = "uploads/$sessid";
// If path/sessid does not exist, create it
if(!is_dir($target_path)){
mkdir("$target_path");
}
// move_uploaded_file($string, target);
foreach ($_FILES['file_to_upload']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES['file_to_upload']['tmp_name'][$key];
$name = $_FILES['file_to_upload']['name'][$key];
// upload/move file to the session dir
move_uploaded_file($tmp_name, "$target_path/$name");
print("<b>File Attached: $name</b><br />");
}
}
?>
|
The dir IS created, the file IS moved. The file isn't corrupt, because the file size is the same as the one I uploaded.
1. BUT when I go to open the file via graphic editor I get: "file is locked"
2. If I just double click in explorer I get "No preview is available"
3. If I try to copy to my desktop I get "Access Denied, make sure file is not write protected or in use".
I thought it may have been the browser, so I killed it. But that didn't work either. I know theres no CHMOD needed on Abyss either. Whats locking/holding this file? _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Fri Oct 28, 2005 3:38 pm Post subject: |
|
|
Sounds like you're still not closing the file correctly - check your process list in task manager and see if PHP is still running after your script should have finished executing... _________________
"Invent an idiot proof webserver and they'll invent a better idiot..." |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Fri Oct 28, 2005 4:03 pm Post subject: |
|
|
I just tried a reboot, and that did not unlock the file. I just don't understand it. Is there some permission setting in the console thats connected to newly created dirs?
I am able to view the file ON the server. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Fri Oct 28, 2005 4:50 pm Post subject: |
|
|
OK - i did some poking around....
Im using simple file sharing. Accoring to http://support.microsoft.com/?id=326549 I will never be able to change the read-only attribute.
So I switched simple file sharing off. Heres the basic rundown on the
uploads folder htdocs/path/upload_script/uploads/
Administrator = Can do anything
Creator/Owner = Can do NOTHING
Everyone = can Modify/read/write/execute
Logged in user("Intranet" - clever name eh?) = Can do NOTHING
Users = read/list and execute
Do I need to change anything? _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Fri Oct 28, 2005 5:17 pm Post subject: [solved] |
|
|
OK - I changed folder permissions for the /uloads/ and child elements.
Went to advanced file sharing.
Clicked properties of folder/security tab/advanced/owner tab/and changed owner to administrator. Make sure to check that child and subfolders get the change too by clicking the checkbox.
This was my first hand at permissions etc. Being a production machine I was afraid to 'experiment'. So far all is well. AND I learned something. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Fri Oct 28, 2005 8:35 pm Post subject: |
|
|
The Inquisitor wrote: |
According to TRUSTpunk Win2k3 is extreamly good for servers. He says it executes PHP faster too because there is no crap running in the background like on other Windows OS's. |
Actually , there's always going to be something running in the background but
according to the information I've gathered , Win2k3 was built from Win2k and
mostly everyone can agree that its a more stable Windows Server OS. |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Fri Oct 28, 2005 8:52 pm Post subject: |
|
|
Actually, after another folder uploads/sessionID/$file was created, i had the same problem again >:(
I dunno whats going on. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Sun Oct 30, 2005 12:39 pm Post subject: |
|
|
lestat wrote: | OK - i did some poking around....
Im using simple file sharing. Accoring to http://support.microsoft.com/?id=326549 I will never be able to change the read-only attribute.
So I switched simple file sharing off. Heres the basic rundown on the
uploads folder htdocs/path/upload_script/uploads/
Administrator = Can do anything
Creator/Owner = Can do NOTHING
Everyone = can Modify/read/write/execute
Logged in user("Intranet" - clever name eh?) = Can do NOTHING
Users = read/list and execute
Do I need to change anything? |
Give all privilages to everyone. Then try it.
If you still can't get to it, download pulist.exe, and see what could possibly be using it.
Install pulist, copy it to C:\WINDOWS\system32. After you've just uploaded a new file, run pulist (Start -> run -> cmd -> pulist.), check the the highest process ID (PID, incase you didn't get it.) and find the corresponding application. (Maybe check the last few, incase an application started since.) _________________
|
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Mon Oct 31, 2005 5:44 pm Post subject: |
|
|
I tried the pulist, and it doesn't indicate anything that has a hold of the folder or file.
Maybe I need to set the /upload/ folder to be shared in some way?
Everytime I change the owner of the folder, the read-only attribute checks itself.
And it's still iin use by something. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
lestat -
Joined: 15 Sep 2003 Posts: 130 Location: GREEN BAY
|
Posted: Mon Oct 31, 2005 10:11 pm Post subject: |
|
|
Still don't know what the problem is/was. I went from using move_uploaded_files() to using copy() and all is well. _________________ XP Pro sp2
Abyss Web Server X2 (v 2.9.3.5)
PHP 5.3.8 |
|
Back to top |
|
|
|