Jump to content


Photo

creating directory


  • Please log in to reply
4 replies to this topic

#1 tryingtolearn

tryingtolearn
  • Members
  • PipPipPip
  • Advanced Member
  • 294 posts

Posted 13 June 2006 - 09:30 PM

Hi all -
I have 2 questions on creating directories.

First - I am using this code to create the directory using the user ID as a subfolder.
This finally got worked out so the permissions were set right and it works.

$oldumask = umask(0);
mkdir("images/$user_id/", 0777);
umask($oldumask);

The first time the user uploads a photo it works fine
But the next photo uploaded is triggering errors since the directory already exists.

I tried adding if else statements but it seems to ignore that.
That leads to the second question,
- when creating the directory it is listed as apache as the owner.
Would this affect any of the error messages (I dont think so because it is all working fine)

So how can write it to only create the directory if it doesnt exist.
This was the last attempt the didnt do anything.
if (is_dir('images/$user_id/')) {
}
else{
$oldumask = umask(0);
mkdir("images/$user_id/", 0777);
umask($oldumask);
}


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 09:48 PM

Remove the trailing slash.
if (!is_dir('images/$user_id')) {
  $oldumask = umask(0);
  mkdir("images/$user_id", 0777);
  umask($oldumask);
}
Also note the use of !

#3 tryingtolearn

tryingtolearn
  • Members
  • PipPipPip
  • Advanced Member
  • 294 posts

Posted 13 June 2006 - 10:07 PM

Thanks thorpe,
Tried that way also - I redid it and by copying and pasting your code just to make sure.

I still get this error -

mkdir(images/5): File exists
Date/Time: 6-13-2006 18:04:10

Well Im saying error - but everything is uploading so is it just a warning or is it an error?
Is there a difference??

Just wondering.


#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 10:20 PM

Sorry... didn't even see this. Change this line...
if (!is_dir('images/$user_id')) {
to...
if (!is_dir("images/$user_id")) {
Note the double quotes.

#5 tryingtolearn

tryingtolearn
  • Members
  • PipPipPip
  • Advanced Member
  • 294 posts

Posted 13 June 2006 - 10:27 PM

Worked like a charm
Thank you for the help.

Those little things like single quotes or double quotes always get me pulling my hair out for hours on end!

I appreciate you taking the time.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users