tryingtolearn Posted June 13, 2006 Share Posted June 13, 2006 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 fineBut 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] Quote Link to comment https://forums.phpfreaks.com/topic/11920-creating-directory/ Share on other sites More sharing options...
trq Posted June 13, 2006 Share Posted June 13, 2006 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/11920-creating-directory/#findComment-45240 Share on other sites More sharing options...
tryingtolearn Posted June 13, 2006 Author Share Posted June 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11920-creating-directory/#findComment-45252 Share on other sites More sharing options...
trq Posted June 13, 2006 Share Posted June 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11920-creating-directory/#findComment-45260 Share on other sites More sharing options...
tryingtolearn Posted June 13, 2006 Author Share Posted June 13, 2006 Worked like a charmThank 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. Quote Link to comment https://forums.phpfreaks.com/topic/11920-creating-directory/#findComment-45264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.