mkdir() file in use or write protected error

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 5:00 pm    Post subject: mkdir() file in use or write protected error Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 12, 2005 5:44 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Wed Oct 12, 2005 5:44 pm    Post subject: Reply with quote

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 View user's profile Send private message
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 5:52 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Wed Oct 12, 2005 6:02 pm    Post subject: Reply with quote

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 View user's profile Send private message
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 7:01 pm    Post subject: [Solved] Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 9:49 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 12, 2005 9:56 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 10:00 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 12, 2005 10:03 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 10:06 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 12, 2005 10:21 pm    Post subject: Reply with quote

Yeh, I have no problems with Abyss. Thats why I run it ;-)
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 10:26 pm    Post subject: [solved] Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Wed Oct 12, 2005 10:30 pm    Post subject: Reply with quote

Hmm weird. Must be good ol' windows!
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Wed Oct 12, 2005 10:37 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Fri Oct 28, 2005 3:29 pm    Post subject: move_uploaded_file() works, but access denied? Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Fri Oct 28, 2005 3:38 pm    Post subject: Reply with quote

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 View user's profile Send private message
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Fri Oct 28, 2005 4:03 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Fri Oct 28, 2005 4:50 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Fri Oct 28, 2005 5:17 pm    Post subject: [solved] Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Oct 28, 2005 8:35 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Fri Oct 28, 2005 8:52 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Oct 30, 2005 12:39 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Mon Oct 31, 2005 5:44 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
lestat
-


Joined: 15 Sep 2003
Posts: 130
Location: GREEN BAY

PostPosted: Mon Oct 31, 2005 10:11 pm    Post subject: Reply with quote

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 View user's profile Send private message AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group