Skip to content

Instantly share code, notes, and snippets.

@aweijnitz
Last active December 29, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweijnitz/7712587 to your computer and use it in GitHub Desktop.
Save aweijnitz/7712587 to your computer and use it in GitHub Desktop.
PHP script to copy ukulele advent calendar submissions using the day of month as base file name (i.e. 1.htm, 1.mp3, 1.jpg on Dec 1st and so on)
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
// Change these to actual directory paths (including trailing slash '/')
$SOURCE_DIR = '/Users/anders/tmp/from/';
$DESTINATION_DIR = '/Users/anders/tmp/to/';
date_default_timezone_set('CET');
$filePrefix = date("j"); // Returns the day of month (ex. '1' for Dec 01)
$htmlFile = $filePrefix . '.htm';
$imgFile = $filePrefix . '.jpg';
$mp3File = $filePrefix . '.mp3';
$files = array($htmlFile, $imgFile, $mp3File);
foreach ($files as $file) {
$FROM = $SOURCE_DIR . $file; // path to source file. Ex 'from/1.htm'
$TO = $DESTINATION_DIR . $file; // path to destination file. Ex. 'to/1.htm'
if(!copy($FROM, $TO)) { // do copy
echo "Failed to copy file $FROM to $TO<br />";
} else
echo "Copied file $FROM<br />";
}
phpinfo();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment