Last active
August 29, 2015 14:19
-
-
Save tomasgreen/c5d01cfa604e2070d225 to your computer and use it in GitHub Desktop.
Change time and move photos to folder by device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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