By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,696 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,696 IT Pros & Developers. It's quick & easy.

create directory name based on system date

P: 44
hi everyone i upload file each an every day so i want to keep track of how many files i uploade a day by creating new directory everytime when i uploade base on the system date.

example
the new directory must be name according to the system date:


$newdir = "system date";

i want my directory name to look like 30January2007
i will be glad if i can get help.
Jan 30 '08 #1
Share this Question
Share on Google+
13 Replies


code green
Expert 100+
P: 1,726
Probably a few methods.
This is a simple example
[PHP]$date = date('dFY');
mkdir('/path/to/directory/'.$date);[/PHP]
Jan 30 '08 #2

P: 44
hi thanks it works .but my script does'nt wanna copy files to the directory that have been created.

i have a source file and destination file:
$source = $_FILES['uploaded']['name'];
and
$destfile= "/home/FTP-shared/comp/". basename(
$_FILES['uploaded']['name']) ;

when i try to uploade it tells me that fail to open the stream.
file not copied.

i will be glad if you can give me idea about that.
Jan 31 '08 #3

code green
Expert 100+
P: 1,726
my script does'nt wanna copy files to the directory
Can you describe (with code) how you are trying to do this.
Jan 31 '08 #4

P: 44
$Tdate = date('dFY');
$Tdir ="/home/FTP-shared/comp/"; //destination
$source = $_FILES['uploaded']['name'];
echo $Tdir."/".$Tdate."<br/>";
if(file_exists($Tdir."/".$Tdate))
{
copy($source, $Tdir."/".$Tdate."/");
}
else
// check if the directory exist or not

{
mkdir($Tdir."/".$Tdate);
echo"directory has been created !<br/>";
echo $source." in new uploader<br/>";
copy( $source, $Tdate."/".$destfile);
}
Jan 31 '08 #5

code green
Expert 100+
P: 1,726
My understanding is the browser renames the uploaded file 'temp_name'
'name' is the original filename.
So to access the file from the browser you need
[PHP]$_FILES['uploadedfile']['tmp_name'];[/PHP]
But I need to revise this subject myself.
Other problems are file permissions and sometimes needing the full path string.
Would move_uploaded_file() be a better option.
copy() is meant for files already in the system
Jan 31 '08 #6

P: 44
Hi thank a lot

yes i understand but the problem is i want to keep the original file name i the file that i am uploading.cause the uploaded file i re name and upload them.so i dont want the renamed file in the completed folder. other altenative based of my explanation.
Jan 31 '08 #7

Markus
Expert 5K+
P: 6,050
What code green said is correct.

You need to use move_uploaded_file

this wont change the file name:

[php]
move_uploaded_file
($_FILES['uploaded]['tmp_name'],
"path/to/directory/" . $_FILES['uploaded']['name']);
[/php]

Note, please check you use only the needed amount of forward slashes to seperate directories (1); from the looks of it you assign more than this.
Jan 31 '08 #8

code green
Expert 100+
P: 1,726
My point was, I'm not sure you have a choice.
I've only played with this a couple of times, but
to access the file you need to use the $_FILE 'temp_name' or is it 'tmp_name'
The original file name is in the index ['name'].
Jan 31 '08 #9

Markus
Expert 5K+
P: 6,050
My point was, I'm not sure you have a choice.
I've only played with this a couple of times, but
to access the file you need to use the $_FILE 'temp_name' or is it 'tmp_name'
The original file name is in the index ['name'].
Preciselly(sp?)

and it's tmp_name

:)
Jan 31 '08 #10

code green
Expert 100+
P: 1,726
Thanks for the help markusn00b
Jan 31 '08 #11

Markus
Expert 5K+
P: 6,050
@ogo: Have a look at this tutorial for file upload using php; you could easily intergrate your directory creation into it (this tutorial is alot cleaner than your way of it.)

@code 9f27410725ab8cc8854a2769c7a516b8: no problamo!
Jan 31 '08 #12

P: 44
thanks i use the move_uploaded_file it works but it dosen't wanna create the folder again.but i will look at it.
Thanks very much you help me through out this
Jan 31 '08 #13

Markus
Expert 5K+
P: 6,050
thanks i use the move_uploaded_file it works but it dosen't wanna create the folder again.but i will look at it.
Thanks very much you help me through out this
Well post up the code you now have (use code tags!) and we'll help you further.
Jan 31 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.