在 php 中上传时附上文件名的日期和时间

Attach date and time with file name while uploading in php

我正在上传一个带有日期时间的文件,但没有发生,这是我的代码:

$time = date('Y-m-d H:i:s');
$filename = $time."-".$filename;
$store = "cvs/".$filename;
move_uploaded_file($tmpfilename, $store);

您的表格应该是这样的:

<form action="" method="post" enctype="multipart/form-data">


   <input type="file" name="myfile" />
   <input type="submit" name="submitbutton" value="Upload" />

  </form>    

php 看起来像这样:

<?php

 $time = date("Y-m-d H:i:s");

 $filename = $time."-".$filename ;

 $tmpname = $_FILES['myfile']['tmp_name'];

 move_uploaded_file($tmpname,"cvs/".$filename);

?>

这应该将文件上传到目标 cvs 并在 $filename 中为其指定名称。您将需要为表单添加安全性和验证,我只是总结了答案。

$time = date("d-m-Y")."-".time() ;
$filename = $time."-".$filename ;
$store = "cvs/".$filename ; 
move_uploaded_file($tmpfilename,$store);
`$(document).ready(function(){
    var titArray = [];  
    $('#calPriceTable .custom-check').click(function(event){
        event.stopPropagation();
        var amount = Number($("#totalAmount").text());
        var price = $(this).closest('td').next('td').next('td').next('td').text();
        var title = $(this).closest('td').next('td').text();
        $("#allItem").text("");

        if ($(this).is(':checked')) {
            amount += Number(price);
            titArray.push(title);
        } else {
            alert(price);
            amount -= Number(price);
            for( var i = 0; i < titArray.length; i++){ if ( titArray[i] === title) { titArray.splice(i, 1); i--; }}

        }   
        //alert(amount);
        $("#totalAmount").text(amount.toFixed(2));
        for( var i = 0; i < titArray.length; i++) {
            var str = "<br>"+titArray[i];
            $("#allItem").append(str);
        }


    });

    $('#calPriceTable #customCheckOther').click(function(event){
        if ($(this).is(':checked')) {
            $("#otherDes").removeAttr('disabled');
            $("#otherAmount").removeAttr('disabled');
        } else {
            $("#otherDes").val('').attr('disabled', true);
            $("#otherAmount").val('').attr('disabled', true);
            //$("#otherAmount").removeAttr('disabled');
        }
    });
});`
<body>

<div class="container">
  <div class="row">
    <div class="col-12">
      <table class="table table-bordered" id="calPriceTable">
        <thead>
          <tr>
            <th scope="col">Select</th>
            <th scope="col">Title</th>
            <th scope="col">Description</th>
            <th scope="col">Price</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>
              <div class="custom-control custom-checkbox">
                  <input type="checkbox" class="custom-control-input custom-check" id="customCheck1">
                  <label class="custom-control-label" for="customCheck1">1</label>
              </div>
            </td>
            <td>Bootstrap 4 CDN and Starter Template</td>
            <td>Cristina</td>
            <td>913</td>
          </tr>
          <tr>
            <td>
              <div class="custom-control custom-checkbox">
                  <input type="checkbox" class="custom-control-input custom-check" id="customCheck2">
                  <label class="custom-control-label" for="customCheck2">2</label>
              </div>
            </td>
            <td>Bootstrap Grid 4 Tutorial and Examples</td>
            <td>Cristina</td>
            <td>1.434</td>
          </tr>
          <tr>
            <td>
              <div class="custom-control custom-checkbox">
                  <input type="checkbox" class="custom-control-input custom-check" id="customCheck3">
                  <label class="custom-control-label" for="customCheck3">3</label>
              </div>
            </td>
            <td>Bootstrap Flexbox Tutorial and Examples</td>
            <td>Cristina</td>
            <td>1.877</td>
          </tr>
          <tr>
            <td>
              <div class="custom-control">
                  <input type="checkbox" class="custom-control-input" id="customCheckOther">
                  <label class="custom-control-label" for="customCheck3">4</label>
              </div>
            </td>
            <td>Other</td>
            <td><input type="text" id="otherDes" name="otherDes" disabled></td>
            <td><input type="number" id="otherAmount" name="otherAmount" disabled></td>
          </tr>
        </tbody>
      </table>
      <div>
      <div>Total Amount : <span id="totalAmount">0</span></div>
      <div>Selected Item : <span id="allItem"></span></div>
      </div>
    </div>
  </div>
</div>
</body>