File Upload and Dir Creation!! Confuzed ;/

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TRN_Webmaster
Forum Newbie
Posts: 3
Joined: Fri Nov 08, 2002 6:08 pm

File Upload and Dir Creation!! Confuzed ;/

Post by TRN_Webmaster »

Hey everyone, i have been trying to figure out how to do this for over a week now, and finally decided to get some help from the forums ;P

Well, i made a script that checks if a dir is present witht he is_dir() function, and if it is not, it creates the dir via mkdir($thedir,0777). I make the dir 777 because i want to be able to upload into it. The problem is though, after the dir is created and the file tries to be copied in, it says another UID owns that dir. It is very frustrating, here is the actual error:
Warning: SAFE MODE Restriction in effect. The script whose uid is 531 is not allowed to access /home/virtual/site27/fst/var/www/html/uploads/2002-01-01 owned by uid 48 in /home/virtual/site27/fst/var/www/html/ul.php on line 8
As you can see, "uploads" i created via FTP and chmodded it to 777. I can upload files perfectly there with no worries. But the trouble comes in, when i have to make the dated dir if it doesnt exits. Because after its made and i try to upload to it, the above error comes up :( Hope thats not too confuzing :!:

Any and all replies are appreciated! E-Mail me at webmaster@tintedreality.net if you would like to send me an example file or a solution.

Thanks very much!!!! :wink:
Tinted Reality Webmaster
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

omg, I never understood SAFE MODE 8O
Just to be sure:
2002-01-01 is successfully created by the same script that can't access it afterwards?
TRN_Webmaster
Forum Newbie
Posts: 3
Joined: Fri Nov 08, 2002 6:08 pm

Post by TRN_Webmaster »

Yes volka, the dir is created and exactly afterwards the copy command executes one or two lines after the dir creation command (same script). It's really got me stumped :?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

a couple of other silly questions

Post by phpScott »

I know these might be silly questions but I had some trouble doing something very simillar.
Have you ftp'd to the site to make sure 2001-01-01 has permissions 777?

The file that is being copied, is it being upload from a client then copied to the new folder or is it an existing file that is being copied?

You are not using copy as a unix command but as a php command?

I found that when I created a new directory in php it seems that now php, or apache, are now the owner of that file and not the user of the site. This makes it really annoying when you want to delete the folders via ftp because you are not the owner, php has to do it for you.

Here is a snippet of the code that I used

Code: Select all

<?php
// create a directory to hold imaged for the new account
     $clientDirI = $root.'/web/accountsImage/'.$this->accnt;
     if (!mkdir($clientDirI, 0777))
     {
        $msg = "error 224 - Create accountsImage directory failed";
        return false;
     }
//copy defualt picture to new account
$mbrPic = $clientDirI."/dl00".$j."_default.jpg";
        $defaultPic = $root."/web/images/defaultPic1S.jpg";
        if (!copy($defaultPic, $mbrPic))
        {
          $msg = "error 225 - Copy default image to clients accountsImage failes";
          return false;
        }


?>
Without getting into mindless detial I have to copy couple of default pictures into a new account.

See what you can use.

phpScott
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Don't run PHP in safe mode, edit php.ini.
TRN_Webmaster
Forum Newbie
Posts: 3
Joined: Fri Nov 08, 2002 6:08 pm

Post by TRN_Webmaster »

phpScott:
- Its a form uploaded file
- Im using php copy() command
- When i ftp in, the chmod is 755 and not 777 like it should be
- I cant access the dir
- My code is very similar to yours

Takuma:
- The admins say its too dangerous and wont let me run in non-safe mode ;x
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

try this variation

Post by phpScott »

You might have to do what is called umask to get the right file permissions.
more info
http://www.php.net/manual/en/function.umask.php
Intergrate this little snippet of code into yours.

Code: Select all

umask(000);
mkdir($dirName, 0777);
should make a directory with permissions 0777.

try it anyway.

phpScott
Post Reply