Skip to content

Instantly share code, notes, and snippets.

@tomasgreen
Last active August 29, 2015 14:19
Show Gist options
  • Save tomasgreen/c5d01cfa604e2070d225 to your computer and use it in GitHub Desktop.
Save tomasgreen/c5d01cfa604e2070d225 to your computer and use it in GitHub Desktop.
Change time and move photos to folder by device
<?php
date_default_timezone_set('Europe/Stockholm');
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
while (false !== ($entry = readdir($handle)))
{
$ext = strtolower(pathinfo($entry, PATHINFO_EXTENSION));
if($ext == "jpg" || $ext == "jpeg")
{
setdatetime($entry);
/*exifdata($entry);*/
echo $ext ." " . $entry . "\n";
} else if ($ext == "mov" || $ext == "avi"){
/*setdatetime($entry);*/
}
}
closedir($handle);
}
function setdatetime($file)
{
$date = substr($file, 0,19);
touch($file, strtotime($date));
}
function exifdata($file)
{
$exif = exif_read_data($file, 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
if($key == "IFD0" && $name == "Make")
{
if(!is_dir($val)) mkdir($val, 0700);
rename($file,"$val/$file");
return;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment