当使用PHP文件上传到新文件夹时,保持修改日期旧日期

时间:2015-01-13 12:14:18

标签: php

HTML:

<form action="" method="post" enctype="multipart/form-data">
    <input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
    <input type="submit" value="Upload!" />
</form>

PHP:

<?php

$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['basedir'];

$valid_formats = array("jpg", "jpeg", "png", "gif", "zip", "bmp");
$path = $upload_dir."/"; // Upload directory
$count = 0;

if( isset( $_POST ) and $_SERVER['REQUEST_METHOD'] == "POST" )
{
  // Loop $_FILES to execute all files
  foreach ( $_FILES['files']['name'] as $f => $name )
  {     
      if ( $_FILES['files']['error'][$f] == 4 )
      {
          continue; // Skip file if any error found
      }        
      if ( $_FILES['files']['error'][$f] == 0 )
      {
          if( ! in_array( pathinfo( $name, PATHINFO_EXTENSION ), $valid_formats ) )
          {
            $message[] = "$name is not a valid format";
            continue; // Skip invalid file formats
          }
          else
          {
                // Move uploaded files. 
                if( copy( $_FILES["files"]["tmp_name"][$f], $path.$name ) )
                $count++;
          }
      }
  }
}

我想保持现在的修改日期为16 December 2014。但是当该文件使用上述代码移动到新文件夹时,文件的修改日期(在新文件夹中)更改为当前日期,即13 January 2015。 在将文件上传到新文件夹时,有没有办法保留修改日期或创建日期?

<code>Sample</code>

0 个答案:

没有答案