note 102719 added to function.touch

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
<?
// 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.