note 102719 added to function.touch

From: Date: Wed, 02 Mar 2011 00:49:17 +0000
Subject: note 102719 added to function.touch
Groups: php.notes 
Request: Send a blank email to php-notes+get-177478@lists.php.net to get a copy of this message
<? // Touch file $image_file and set creation date based on date from EXIF // // @return Integer // NULL - if no EXIF data // 1 - creation date changed // 2 - no change needed (same dates) // 0 - colud not touch function touch_exif($image_file) { $info=exif_read_data($image_file); if (!$info) return NULL; $datetime=isset($info['DateTime'])? $info['DateTime']: (isset($info['DateTimeOriginal'])? $info['DateTimeOriginal']: (isset($info['DateTimeDigitized'])? $info['DateTimeDigitized']: false)); $filetime=isset($info['FileDateTime'])? $info['FileDateTime']: false; if(!$datetime) return NULL; //0 yyyy:mm:dd, 1 hh:mm:ss $datetime=explode(' ',$datetime); list($y,$m,$d)=explode(':', $datetime[0]); list($hh,$mm,$ss)=explode(':', $datetime[1]); $datetime=mktime($hh, $mm, $ss, $m, $d, $y, 0); if ($datetime==$filetime) return 2; return (int)touch($argv[1], $datetime); } ?> Example of usage. Command line creation date changer. <? if($argc<2) die('Usage: php '.$argv[0].' image_name.jpg'); switch (touch_exif($argv[1])) { case NULL:die('EXIF date not found'); case 0:die('Fail. Do i have access?'); case 1:die('Success'); case 2:die('No change needed'); } ?> ---- Server IP: 78.41.111.10 Probable Submitter: 95.220.169.54 ---- Manual Page -- http://www.php.net/manual/en/function.touch.php Edit -- https://master.php.net/note/edit/102719 Del: integrated -- https://master.php.net/note/delete/102719/integrated Del: useless -- https://master.php.net/note/delete/102719/useless Del: bad code -- https://master.php.net/note/delete/102719/bad+code Del: spam -- https://master.php.net/note/delete/102719/spam Del: non-english -- https://master.php.net/note/delete/102719/non-english Del: in docs -- https://master.php.net/note/delete/102719/in+docs Del: other reasons-- https://master.php.net/note/delete/102719 Reject -- https://master.php.net/note/reject/102719 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177478) next »