Jump to content

Archived

This topic is now archived and is closed to further replies.

tryingtolearn

creating directory

Recommended Posts

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.

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

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.
[code]if (is_dir('images/$user_id/')) {
}
else{
$oldumask = umask(0);
mkdir("images/$user_id/", 0777);
umask($oldumask);
}[/code]

Share this post


Link to post
Share on other sites
Remove the trailing slash.
[code]
if (!is_dir('images/$user_id')) {
  $oldumask = umask(0);
  mkdir("images/$user_id", 0777);
  umask($oldumask);
}
[/code]
Also note the use of !

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sorry... didn't even see this. Change this line...
[code]
if (!is_dir('images/$user_id')) {
[/code]
to...
[code]
if (!is_dir("images/$user_id")) {
[/code]
Note the double quotes.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.