note 63852 deleted from function.mkdir by bjori

From: Date: Sun, 02 Apr 2006 14:43:15 +0000
Subject: note 63852 deleted from function.mkdir by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107167@lists.php.net to get a copy of this message
Note Submitter: John Reason: bad code ---- I'm planning on having a members upload pics sometime soon, and instead of having all of the picture in one folder I want to put the pictures into a folder that was the date of the upload. do for example, if they uploaded the file april 1st 2006, I wanted to create a folders like so within my gallery folder gallery/2006/04/1/UPLOADED.htm I was using the mkdir() funstion, and then setting the chmod in the function to 0777 so the files could be uploaded and deleted when need be. I then found that even though I used - mkdir("path/to/folder", 0777); I would get an error. so heres what I then did. <?php if(isset($_POST['upload'])){ $year = date("Y"); $month = date("m"); $day = date("d"); if(!is_dir("gallery/$year")){ echo "no directory found for year so creating that.."; mkdir("gallery/$year"); chmod("gallery/$year", 0777); echo "--- done<br>"; } else { echo "year folder found so go to next step<br>"; } if(!is_dir("gallery/$year/$month")){ echo "month folder not found.. so create it.."; mkdir("gallery/$year/$month"); chmod("gallery/$year/$month", 0777); echo "--- done<br>"; } else { echo "month folder found so go to next step<br>"; } if(!is_dir("gallery/$year/$month/$day")){ echo "day folder not found.. so create it.."; mkdir("gallery/$year/$month/$day"); chmod("gallery/$year/$month/$day", 0777); echo "--- done<br>"; } else { echo "day folder found so go to next step<br>"; } if(!is_dir("gallery/$year/$month/$day")){ die("strange error.."); } else { echo "folder found, now upload the picture and put them all in there."; } } ?> even though the codes not finished above, heres the outcome. no directory found for year so creating that..--- done month folder not found.. so create it..--- done day folder not found.. so create it..--- done folder found, now upload the picture and put them all in there. now I can still remove the files or folders through ftp if I wanted to.

« previous php.notes (#107167) next »