473,511 Members | 16,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Appending Date/Time Stamp to filename

Don
Hi all,

With regards to the following, how do I append the datetimestamp to
the filenames in the form? The files are processed using the PHP
script that follows below.

Thanks in advance,
Don

Following running on client-side:
--------------------------------------

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">
function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}
</script>
<form enctype="multipart/form-data" action="http://notRealURL.php"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<input type="hidden" name="MAX_INPUT_TIME" value="280" />
Send file 1: <input name="userfile[]" type="file" /><br />
Send file 2: <input name="userfile[]" type="file" /><br />
Send file 3: <input name="userfile[]" type="file" /><br />
Send file 4: <input name="userfile[]" type="file" /><br />
<input type="submit" value="Send File" />
</form>
</body>

Following server-side PHP script receives and uploads the files:
---------------------------------------------------------------------------

<?php
$uploaddir = 'picturevault/';
$uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
$uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
$uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
$uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];

print "<pre>";

if ($_FILES['userfile']['size'][0] != 0) {
if (move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$uploadfile1)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging
info:\n";
print_r($_FILES);
}
print "</pre>";
}

if ($_FILES['userfile']['size'][1] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][1],
$uploadfile2);

if ($_FILES['userfile']['size'][2] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][2],
$uploadfile3);

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][3],
$uploadfile4);

print "</pre>";

?>


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #1
7 19578
Lee
Don said:

Hi all,

With regards to the following, how do I append the datetimestamp to
the filenames in the form? The files are processed using the PHP
script that follows below. function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}
</script>


That's a very bad format for a date stamp. Ignoring the
similar problems with hours minutes and seconds, how would
you interpret the date stamp: "1122004"? Is that November
2nd, or is it January 12th? You need to pad any single-digit
values to two digits. Then, you'll probably want to change
the order to Year,Month,Date,Hours,Minutes,Seconds, so you
can sort the values easily.

If you want to pass the client's clock time to the server,
there's no need to append it to the filename on the client
side (not possible, anyway). Just pass it in a hidden form
field. However, it would be simpler and more reliable to
have your PHP script determine the time on the server. You
never know whether the client's clock is correct, and you're
not recording their timezone.

Jul 23 '05 #2
Don
On 26 Sep 2004 09:20:16 -0700, Lee <RE**************@cox.net> wrote:
Don said:

Hi all,

With regards to the following, how do I append the datetimestamp to
the filenames in the form? The files are processed using the PHP
script that follows below.

function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}
</script>


That's a very bad format for a date stamp. Ignoring the
similar problems with hours minutes and seconds, how would
you interpret the date stamp: "1122004"? Is that November
2nd, or is it January 12th? You need to pad any single-digit
values to two digits. Then, you'll probably want to change
the order to Year,Month,Date,Hours,Minutes,Seconds, so you
can sort the values easily.

If you want to pass the client's clock time to the server,
there's no need to append it to the filename on the client
side (not possible, anyway). Just pass it in a hidden form
field. However, it would be simpler and more reliable to
have your PHP script determine the time on the server. You
never know whether the client's clock is correct, and you're
not recording their timezone.


Hi Lee,

I'm not done with function datetimestamp. I intend to do as you
suggested.

Regarding passing the datetimestamp to the PHP script on the
server-side, can you show me some code on the client-side (html),and
in the PHP script on the server-side? I'm quite new at JS
programming, and am not sure how to go about it. I will still need to
have the server-side PHP script append that datetimestamp to the file
name. The purpose of these scripts is to allow uploading of 1 - 4
picture fiiles from the client's desktop. The reason for appending
the datetime to the file name is to ensure another client can't easily
overwrite a previous client's upload.

Here's the client-side html:
--------------------------------
<form enctype="multipart/form-data"
action="http://notRealURL.com/cpcenhanced/processpics.php"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
<input type="hidden" name="MAX_INPUT_TIME" value="280" />
Send file 1: <input name="userfile[]" type="file" /><br />
Send file 2: <input name="userfile[]" type="file" /><br />
Send file 3: <input name="userfile[]" type="file" /><br />
Send file 4: <input name="userfile[]" type="file" /><br />
<input type="submit" value="Send File" />
</form>

And, here's the server-side PHP:
---------------------------------------
<?php
$uploaddir = 'picturevault/';
$uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
$uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
$uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
$uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];

print "<pre>";

if ($_FILES['userfile']['size'][0] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$uploadfile1);

if ($_FILES['userfile']['size'][1] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][1],
$uploadfile2);

if ($_FILES['userfile']['size'][2] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][2],
$uploadfile3);

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][3],
$uploadfile4);

print "</pre>";

?>

Thank you
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #3
Don wrote:

Hi Lee,

I'm not done with function datetimestamp. I intend to do as you
suggested.
If you do it on the server, then you have no need to attempt to do it on
the client. As Lee said, you can't do what you are wanting anyway. And
even if you could modify the value of a file input field, it's still not
the best way to do it.
Regarding passing the datetimestamp to the PHP script on the
server-side, can you show me some code on the client-side (html),and
in the PHP script on the server-side? I'm quite new at JS
programming, and am not sure how to go about it. I will still need to
have the server-side PHP script append that datetimestamp to the file
name. The purpose of these scripts is to allow uploading of 1 - 4
picture fiiles from the client's desktop. The reason for appending
the datetime to the file name is to ensure another client can't easily
overwrite a previous client's upload.


That is why you need to append the datetime on the server, not on the
client. Let's say Lee and I both attach files, and the time on *our*
computers generate the exact same date/time stamp. Then, you have the
problem. It also does not prevent my clock from being wrong and me
resetting it and overwriting my own files. By doing the date time stamp
on the server, you have a lot more control over the time stamp.

A better, more reliable, method would be to assign them numbers in
numerical order. Check the last file name, increase its counter, and
carry on.

<--snip-->
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4
Don
On Sun, 26 Sep 2004 15:21:41 -0400, Randy Webb
<Hi************@aol.com> wrote:
Don wrote:

Hi Lee,

I'm not done with function datetimestamp. I intend to do as you
suggested.


If you do it on the server, then you have no need to attempt to do it on
the client. As Lee said, you can't do what you are wanting anyway. And
even if you could modify the value of a file input field, it's still not
the best way to do it.
Regarding passing the datetimestamp to the PHP script on the
server-side, can you show me some code on the client-side (html),and
in the PHP script on the server-side? I'm quite new at JS
programming, and am not sure how to go about it. I will still need to
have the server-side PHP script append that datetimestamp to the file
name. The purpose of these scripts is to allow uploading of 1 - 4
picture fiiles from the client's desktop. The reason for appending
the datetime to the file name is to ensure another client can't easily
overwrite a previous client's upload.


That is why you need to append the datetime on the server, not on the
client. Let's say Lee and I both attach files, and the time on *our*
computers generate the exact same date/time stamp. Then, you have the
problem. It also does not prevent my clock from being wrong and me
resetting it and overwriting my own files. By doing the date time stamp
on the server, you have a lot more control over the time stamp.

A better, more reliable, method would be to assign them numbers in
numerical order. Check the last file name, increase its counter, and
carry on.

<--snip-->

Hi Randy,

The reason I wanted to append the date/time stamp on the client-side
is that that same composite file name is then going to be used in the
same client-side page for other purposes. So, I need to know the
date/time stamp before I submit the form. However, I like even better
your idea of running a sequence counter on the server side. However,
again the client side page containing JS will need to know the
sequence number assigned by PHP on the server side. How do I
communicate back to the client page that submitted the form the
sequence number determined by the server side PHP? I'm finding this
quite difficult, but I sure am learning a lot.

Thanks for your help.
Don
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #5
Don wrote:

<--snip-->

Hi Randy,

The reason I wanted to append the date/time stamp on the client-side
is that that same composite file name is then going to be used in the
same client-side page for other purposes. So, I need to know the
date/time stamp before I submit the form. However, I like even better
your idea of running a sequence counter on the server side. However,
again the client side page containing JS will need to know the
sequence number assigned by PHP on the server side. How do I
communicate back to the client page that submitted the form the
sequence number determined by the server side PHP? I'm finding this
quite difficult, but I sure am learning a lot.


When the form gets submitted to the server, the page that the server
returns can have the image names in it. Or, post it to a hidden IFrame
and read them from there. For the non-JS browsing audience, the first
scenario is preferred.

Page1.php submits the images to Page2.php, Page2.php can get the names
of the images and include them in the page it returns. echo $imageName;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
JRS: In article <7k********************************@4ax.com>, dated
Sun, 26 Sep 2004 07:04:22, seen in news:comp.lang.javascript, Don
<no@adr.com> posted :
function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}


The concatenation is more effectively done as

var sToday = "" +
today.getMonth()+1) +
today.getDate() +
today.getYear() +
today.getHours() +
today.getMinutes() +
today.getSeconds() ;

Unless you use field separators or leading zeroes or both, the result
will be horribly ambiguous if M<10 xor D<10, or any but not all of h m s
<10 (that assumes the year to be recognisable).

FFF is unwise for general use; follow FIPS 4.1 (if American) or ISO
8601.

The following gives a universally comprehensible result, and, after
thinking about it for the first time, will seem far simpler.

with (new Date()) sToday = ((((
getYear()*100 + (getMonth()+1))*100 + getDate())*100 +
getHours())*100 + getMinutes())*100 + getSeconds()

For leading zeroes AND separators, use <FAQENTRY>

function LZ(x) { return (x<0||x>=10?"":"0") + x }
*** DO NOT MULTI-POST ***
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #7
Don
On Sun, 26 Sep 2004 22:06:10 +0100, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <7k********************************@4ax.com>, dated
Sun, 26 Sep 2004 07:04:22, seen in news:comp.lang.javascript, Don
<no@adr.com> posted :
function datetimestamp()
{
var today = new Date();
var sToday = (today.getMonth()+1).toString();
sToday += today.getDate().toString();
sToday += today.getYear().toString();
sToday += today.getHours().toString();
sToday += today.getMinutes().toString();
sToday += today.getSeconds().toString();
return sToday;
}


The concatenation is more effectively done as

var sToday = "" +
today.getMonth()+1) +
today.getDate() +
today.getYear() +
today.getHours() +
today.getMinutes() +
today.getSeconds() ;

Unless you use field separators or leading zeroes or both, the result
will be horribly ambiguous if M<10 xor D<10, or any but not all of h m s
<10 (that assumes the year to be recognisable).

FFF is unwise for general use; follow FIPS 4.1 (if American) or ISO
8601.

The following gives a universally comprehensible result, and, after
thinking about it for the first time, will seem far simpler.

with (new Date()) sToday = ((((
getYear()*100 + (getMonth()+1))*100 + getDate())*100 +
getHours())*100 + getMinutes())*100 + getSeconds()

For leading zeroes AND separators, use <FAQENTRY>

function LZ(x) { return (x<0||x>=10?"":"0") + x }
*** DO NOT MULTI-POST ***

Thanks for your help John. Your function looks much better.
Regards,
Don
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8578
by: akoper | last post by:
I have a table that is a project. Each record is a task in the project. One field in each record is a date/time stamp for when that task was completed. I need to be able to: 1) compute how much...
6
13580
by: Mike Charney | last post by:
Is there a way to check a files date and time stamp from VBA in access. I have a need check a date stamp on a file that I am importing. Thanks in advance, Mike m charney at dunlap hospital...
5
2094
by: Des | last post by:
I have to do an events calender for a church. The events display will be limited to that week. If someone went in today Wed 24th I want to display 21st to 27th. I dont want any code samples, just...
3
17540
by: phried1 | last post by:
I have created a form and inserted the following tables: Date Entered Time Entered Date Modified Time Modified Essentially how and where can I have these dates and times recorded so when the...
1
7282
by: Susan Bricker | last post by:
Greetings. I have a report (actually all of my reports in an MDB) that I want to date/time stamp at the bottom. Previously, I had used the builtin function of Now(). I thought that would give...
1
3816
by: Justin | last post by:
When running VMSTAT 3 5, in provides a snapshot every 3 seconds for 5 intervals. Is there a way to add date / time as one of the parameters (AIX environment)? Thanks, jb
4
6791
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
1
2073
by: 6afraidbecause789 | last post by:
Hi - I am using a Date/Time Picker popup form for users to choose a a date and time for use on a separate entry form. The date/time on the entry form is actually entered automatically as a...
16
4432
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.