473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

create directory name based on system date

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
13 6598
code green
1,726 Expert 1GB
Probably a few methods.
This is a simple example
[PHP]$date = date('dFY');
mkdir('/path/to/directory/'.$date);[/PHP]
Jan 30 '08 #2
ogo796
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
1,726 Expert 1GB
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
ogo796
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
1,726 Expert 1GB
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
ogo796
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
6,050 Expert 4TB
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
1,726 Expert 1GB
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
6,050 Expert 4TB
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
1,726 Expert 1GB
Thanks for the help markusn00b
Jan 31 '08 #11
Markus
6,050 Expert 4TB
@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
ogo796
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
6,050 Expert 4TB
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

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

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
8
by: James Owens | last post by:
I'm a relative newbie, interested in storing the information from several server directories and subdirectories in XML so that I can present it selectively using XSL (all files updated today or...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
28
by: Peter Oliphant | last post by:
I have written a program using MS VS VC++ 2005 Express, /cli pure. Upon compiling it it works fine in the GUI development environment. It also works fine as a Debug stand-alone. ut I had an odd...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.