473,804 Members | 2,931 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.getMinute s().toString();
sToday += today.getSecond s().toString();
return sToday;
}
</script>
<form enctype="multip art/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_f ile($_FILES['userfile']['tmp_name'][1],
$uploadfile2);

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

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_f ile($_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 19635
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.getMinute s().toString();
sToday += today.getSecond s().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.getMinute s().toString();
sToday += today.getSecond s().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="multip art/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_f ile($_FILES['userfile']['tmp_name'][0],
$uploadfile1);

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

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

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_f ile($_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.javas cript 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.javas cript 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.getMinute s().toString();
sToday += today.getSecond s().toString();
return sToday;
}


The concatenation is more effectively done as

var sToday = "" +
today.getMonth( )+1) +
today.getDate() +
today.getYear() +
today.getHours( ) +
today.getMinute s() +
today.getSecond s() ;

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())*1 00 + 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.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.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.de mon.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.getMinute s().toString();
sToday += today.getSecond s().toString();
return sToday;
}


The concatenation is more effectively done as

var sToday = "" +
today.getMonth( )+1) +
today.getDate() +
today.getYear() +
today.getHours( ) +
today.getMinute s() +
today.getSecond s() ;

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())*1 00 + 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
8594
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 time has passed between each date/time stamp and 2) compute how much time has passed between the first and last date/time stamp (total project time). This involves a self join, and I have nearly gotten it to work, but I need a little more help. ...
6
13598
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 dot org
5
2109
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 the functions that find the day of week and a function that can (in this case) subtract 3 days to get sunday and add 7 for saterday. I can do the rest. Desmond.
3
17614
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 user creates a new record that date and time stamp is populating as well as if the user modifies the data, that date and time stamp is populationg. Whereby if the record was created yesterday, and the user modified the record today, i would see...
1
7299
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 me a date and time value in the format: "month day, year hour:minutes:seconds". However, I noticed that only the date was printing (e.g.; January 23, 2006). This is in Access 2000. BTW ... The way I display the date/time stamp in a text field...
1
3837
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
6812
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 allows the employee to enter their UserID and select "Login" or "Logout" and then click a submit. When the submit button is clicked, I want the application to dum the NT Userename, UserID, status (Login or Logout) and a date/time stamp into an MS Access...
1
2090
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 date/time stamp when a user enters a record. So, the popup form is only necessary when a user needs to change the date/time. To make this more user-friendly...there will be times when a user will be away from the computer, and therefore, will have to...
16
4469
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 22:02:51? (24 hour day is fine) How about the date after 02/28/04 is 02/29/04, or the date after 09/30/08 is 10/01/08?
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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 we have to send another system

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.