note 63852 added to function.mkdir
| From: | John at osu1 dot php dot net | Date: | Sun, 02 Apr 2006 06:43:08 +0000 |
| Subject: | note 63852 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107150@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 64.71.164.2
Probable Submitter: 166.82.177.161
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- http://master.php.net/note/edit/63852
Del: integrated -- http://master.php.net/note/delete/63852/integrated
Del: useless -- http://master.php.net/note/delete/63852/useless
Del: bad code -- http://master.php.net/note/delete/63852/bad+code
Del: spam -- http://master.php.net/note/delete/63852/spam
Del: non-english -- http://master.php.net/note/delete/63852/non-english
Del: in docs -- http://master.php.net/note/delete/63852/in+docs
Del: other reasons-- http://master.php.net/note/delete/63852
Reject -- http://master.php.net/note/reject/63852
Search -- http://master.php.net/manage/user-notes.php