Appending Date/Time Stamp to filename

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Don (no_at_adr.com)
Date: 09/26/04


Date: Sun, 26 Sep 2004 07:05:55 -0700

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! =-----



Relevant Pages

  • Re: Problems with mkdir() and is_dir()
    ... directory in the uploads subdirectory. ... Here is a copy of a smaller script I threw ... The last two, PDFs and somecrap, are folders created with mkdir(). ... .pngs are files uploaded via a PHP script. ...
    (comp.lang.php)
  • Re: [PHP] Disabling the built-in POST handler
    ... I need to handle very large file uploads and push the data into a socket. ... again inside the script and pushing it into the socket is very inefficient ... Is there a way to completely disable the built-in POST form data handling ... of PHP and handle the data inside the script by reading php://input? ...
    (php.general)
  • Re: [PHP] Disabling the built-in POST handler
    ... I need to handle very large file uploads and push the data into a socket. ... Having php to write everything to a temporary file, then reading it ... again inside the script and pushing it into the socket is very inefficient ... of PHP and handle the data inside the script by reading php://input? ...
    (php.general)
  • PHP SCRIPT
    ... php classified script ... guestbook ardguest free php guestbook script ... php file upload script ...
    (sci.chem.labware)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)