[ PHPXref.com ] [ Generated: Sun Jul 20 19:44:41 2008 ] [ PHP JPEG Metadata 1.11 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> Edit_File_Info.php (source)

   1  <?php
   2  
   3  
   4  /****************************************************************************

   5  *

   6  * Filename:     Edit_File_Info.php

   7  *

   8  * Description:  Allows the user to edit the metadata of an image over the internet

   9  *               in the same way that Photoshop edits 'File Info' data

  10  *               This file provides only the html for a form containing the file info

  11  *               input fields. The rest of the html file must be provided by the calling script.

  12  *               $outputfilename must always be defined - it is ne name of the file which

  13  *               have the metadata changed after the form has been submitted

  14  *

  15  *               This file has several modes of operation:

  16  *

  17  *               1) If $new_ps_file_info_array is defined then it's data will be used

  18  *                  to fill the fields.

  19  *               2) If $new_ps_file_info_array is not defined but $filename is defined,

  20  *                  then the file info fields will be filled from the metadata in the file specified

  21  *               3) If $new_ps_file_info_array is not defined but $filename and $default_ps_file_info_array

  22  *                  are defined, then the file info fields will be filled from the metadata

  23  *                  in the file specified, but where fields are blank, they will be filled from $default_ps_file_info_array

  24  *               4) Otherwise the fields will be blank

  25  *

  26  *               See Edit_File_Info_Example.php for an example of usage

  27  *

  28  * Author:       Evan Hunter

  29  *

  30  * Date:         17/11/2004

  31  *

  32  * Project:      PHP JPEG Metadata Toolkit

  33  *

  34  * Revision:     1.11

  35  *

  36  * Changes:      1.10 -> 1.11 : Changed displayed toolkit version numbers to reference Toolkit_Version.php

  37  *

  38  * URL:          http://electronics.ozhiker.com

  39  *

  40  * Copyright:    Copyright Evan Hunter 2004

  41  *

  42  * License:      This file is part of the PHP JPEG Metadata Toolkit.

  43  *

  44  *               The PHP JPEG Metadata Toolkit is free software; you can

  45  *               redistribute it and/or modify it under the terms of the

  46  *               GNU General Public License as published by the Free Software

  47  *               Foundation; either version 2 of the License, or (at your

  48  *               option) any later version.

  49  *

  50  *               The PHP JPEG Metadata Toolkit is distributed in the hope

  51  *               that it will be useful, but WITHOUT ANY WARRANTY; without

  52  *               even the implied warranty of MERCHANTABILITY or FITNESS

  53  *               FOR A PARTICULAR PURPOSE.  See the GNU General Public License

  54  *               for more details.

  55  *

  56  *               You should have received a copy of the GNU General Public

  57  *               License along with the PHP JPEG Metadata Toolkit; if not,

  58  *               write to the Free Software Foundation, Inc., 59 Temple

  59  *               Place, Suite 330, Boston, MA  02111-1307  USA

  60  *

  61  *               If you require a different license for commercial or other

  62  *               purposes, please contact the author: evan@ozhiker.com

  63  *

  64  ***************************************************************************/
  65  
  66  
  67  
  68          include  'Toolkit_Version.php';          // Change: added as of version 1.11

  69  
  70          // Check for operation modes 2 or 3

  71          // i.e. $filename is defined, and $new_ps_file_info_array is not

  72          if ( ( ! isset( $new_ps_file_info_array ) ) &&
  73               ( isset( $filename ) ) &&
  74               ( is_string( $filename ) ) )
  75          {
  76                  // Hide any unknown EXIF tags

  77                  $GLOBALS['HIDE_UNKNOWN_TAGS'] = TRUE;
  78  
  79                  // Accessing the existing file info for the specified file requires these includes

  80                  include  'JPEG.php';
  81                  include  'XMP.php';
  82                  include  'Photoshop_IRB.php';
  83                  include  'EXIF.php';
  84                  include  'Photoshop_File_Info.php';
  85  
  86                  // Retrieve the header information from the JPEG file

  87                  $jpeg_header_data = get_jpeg_header_data( $filename );
  88  
  89                  // Retrieve EXIF information from the JPEG file

  90                  $Exif_array = get_EXIF_JPEG( $filename );
  91  
  92                  // Retrieve XMP information from the JPEG file

  93                  $XMP_array = read_XMP_array_from_text( get_XMP_text( $jpeg_header_data ) );
  94  
  95                  // Retrieve Photoshop IRB information from the JPEG file

  96                  $IRB_array = get_Photoshop_IRB( $jpeg_header_data );
  97  
  98                  // Retrieve Photoshop File Info from the three previous arrays

  99                  $new_ps_file_info_array = get_photoshop_file_info( $Exif_array, $XMP_array, $IRB_array );
 100  
 101  
 102  
 103                  // Check if there is an array of defaults available

 104                  if ( ( isset( $default_ps_file_info_array) ) &&
 105                       ( is_array( $default_ps_file_info_array) ) )
 106                  {
 107                          // There are defaults defined

 108  
 109                          // Check if there is a default for the date defined

 110                          if ( ( ! array_key_exists( 'date', $default_ps_file_info_array ) ) ||
 111                               ( ( array_key_exists( 'date', $default_ps_file_info_array ) ) &&
 112                                 ( $default_ps_file_info_array['date'] == '' ) ) )
 113                          {
 114                                  // No default for the date defined

 115                                  // figure out a default from the file

 116  
 117                                  // Check if there is a EXIF Tag 36867 "Date and Time of Original"

 118                                  if ( ( $Exif_array != FALSE ) &&
 119                                       ( array_key_exists( 0, $Exif_array ) ) &&
 120                                       ( array_key_exists( 34665, $Exif_array[0] ) ) &&
 121                                       ( array_key_exists( 0, $Exif_array[0][34665] ) ) &&
 122                                       ( array_key_exists( 36867, $Exif_array[0][34665][0] ) ) )
 123                                  {
 124                                          // Tag "Date and Time of Original" found - use it for the default date

 125                                          $default_ps_file_info_array['date'] = $Exif_array[0][34665][0][36867]['Data'][0];
 126                                          $default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
 127                                  }
 128                                 // Check if there is a EXIF Tag 36868 "Date and Time when Digitized"

 129                                  else if ( ( $Exif_array != FALSE ) &&
 130                                       ( array_key_exists( 0, $Exif_array ) ) &&
 131                                       ( array_key_exists( 34665, $Exif_array[0] ) ) &&
 132                                       ( array_key_exists( 0, $Exif_array[0][34665] ) ) &&
 133                                       ( array_key_exists( 36868, $Exif_array[0][34665][0] ) ) )
 134                                  {
 135                                          // Tag "Date and Time when Digitized" found - use it for the default date

 136                                          $default_ps_file_info_array['date'] = $Exif_array[0][34665][0][36868]['Data'][0];
 137                                          $default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
 138                                  }
 139                                  // Check if there is a EXIF Tag 306 "Date and Time"

 140                                  else if ( ( $Exif_array != FALSE ) &&
 141                                       ( array_key_exists( 0, $Exif_array ) ) &&
 142                                       ( array_key_exists( 306, $Exif_array[0] ) ) )
 143                                  {
 144                                          // Tag "Date and Time" found - use it for the default date

 145                                          $default_ps_file_info_array['date'] = $Exif_array[0][306]['Data'][0];
 146                                          $default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
 147                                  }
 148                                  else
 149                                  {
 150                                          // Couldn't find an EXIF date in the image

 151                                          // Set default date as creation date of file

 152                                          $default_ps_file_info_array['date'] = date ("Y-m-d", filectime( $filename ));
 153                                  }
 154                          }
 155  
 156                          // Cycle through all the elements of the default values array

 157                          foreach( $default_ps_file_info_array as $def_key =>$default_item )
 158                          {
 159                                  // Check if the current element is Keywords or

 160                                  // Supplemental Categories as these are arrays

 161                                  // and need to be treated differently

 162                                  if ( ( strcasecmp( $def_key, "keywords" ) == 0 ) ||
 163                                       ( strcasecmp( $def_key, "supplementalcategories" ) == 0 ) )
 164                                  {
 165                                          // Keywords or Supplemental Categories found

 166                                          // Check if the File Info from the file is empty for this element

 167                                          // and if there are default values in this array element

 168                                          if ( ( count( $new_ps_file_info_array[ $def_key ] ) == 0 ) &&
 169                                               ( is_array( $default_item ) ) &&
 170                                               ( count( $default_item ) >= 0 ) )
 171                                          {
 172                                                  // The existing file info is empty, and there are

 173                                                  // defaults - add them

 174                                                  $new_ps_file_info_array[ $def_key ] = $default_item;
 175                                          }
 176                                  }
 177                                  // Otherwise, this is not an array element, just check if it is blank in the existing file info

 178                                  else if ( trim( $new_ps_file_info_array[ $def_key ] ) == "" )
 179                                  {
 180                                          // The existing file info is blank, add the default value

 181                                          $new_ps_file_info_array[ $def_key ] = $default_item;
 182                                  }
 183  
 184                          }
 185                  }
 186          }
 187          // Check for operation mode 4 - $new_ps_file_info_array and $filename are not defined,

 188          else if ( ( ( !isset($new_ps_file_info_array) ) || ( ! is_array($new_ps_file_info_array) ) ) &&
 189                    ( ( !isset($filename) ) || ( ! is_string( $filename ) ) ) )
 190          {
 191                  // No filename or new_ps_file_info_array defined, create a blank file info array to display

 192                  $new_ps_file_info_array = array(
 193                        "title" => "",
 194                        "author" => "",
 195                        "authorsposition" => "",
 196                        "caption" => "",
 197                        "captionwriter" => "",
 198                        "jobname" => "",
 199                        "copyrightstatus" => "",
 200                        "copyrightnotice" => "",
 201                        "ownerurl" => "",
 202                        "keywords" => array(),
 203                        "category" => "",
 204                        "supplementalcategories" => array(),
 205                        "date" => "",
 206                        "city" => "",
 207                        "state" => "",
 208                        "country" => "",
 209                        "credit" => "",
 210                        "source" => "",
 211                        "headline" => "",
 212                        "instructions" => "",
 213                        "transmissionreference" => "",
 214                        "urgency" => "" );
 215          }
 216  
 217  
 218  
 219  /***************************************************************************

 220  *

 221  * Now output the actual HTML form

 222  *

 223  ***************************************************************************/
 224  
 225  ?>
 226  
 227  
 228  
 229  
 230          <form name="EditJPEG" action="Write_File_Info.php" method="post">
 231  
 232  
 233          <?php echo "<input name=\"filename\" type=\"hidden\" value=\"$outputfilename\">"; ?>
 234  
 235                  <table>
 236  
 237                          <tr>
 238                                  <td>
 239                                          Title
 240                                  </td>
 241                                  <td>
 242                                          <?php
 243                                          echo "<input size=49 name=\"title\" type=\"text\" value=\"". $new_ps_file_info_array[ 'title' ] ."\">";
 244                                          ?>
 245                                  </td>
 246                          </tr>
 247  
 248                          <tr>
 249                                  <td>
 250                                          Author
 251                                  </td>
 252                                  <td>
 253                                          <?php
 254                                          echo "<input size=49 name=\"author\" type=\"text\" value=\"". $new_ps_file_info_array[ 'author' ] ."\">";
 255                                          ?>
 256                                  </td>
 257                          </tr>
 258  
 259                          <tr>
 260                                  <td>
 261                                          Authors Position
 262                                  </td>
 263                                  <td>
 264                                          <?php
 265                                                  echo "<input size=49 name=\"authorsposition\" type=\"text\" value=\"". $new_ps_file_info_array[ 'authorsposition' ] ."\"> - Note: not used in Photoshop 7 or higher";
 266                                          ?>
 267                                  </td>
 268                          </tr>
 269  
 270                          <tr>
 271                                  <td>
 272                                          Description
 273                                  </td>
 274                                  <td>
 275                                          <textarea name="caption" rows=3 cols=37 wrap="off"><?php echo $new_ps_file_info_array[ 'caption' ]; ?></textarea>
 276                                  </td>
 277                          </tr>
 278  
 279                          <tr>
 280                                  <td>
 281                                          Description Writer
 282                                  </td>
 283                                  <td>
 284                                          <?php
 285                                          echo "<input size=49 name=\"captionwriter\" type=\"text\" value=\"". $new_ps_file_info_array[ 'captionwriter' ] ."\">";
 286                                          ?>
 287                                  </td>
 288                          </tr>
 289  
 290  
 291                          <tr>
 292                                  <td>
 293                                          Keywords
 294                                  </td>
 295                                  <td>
 296                                          <textarea name="keywords" rows=3 cols=37 wrap="off"><?php
 297                                                                                                  foreach( $new_ps_file_info_array[ 'keywords' ] as $keyword )
 298                                                                                                  {
 299                                                                                                          echo "$keyword&#xA;";
 300                                                                                                  }
 301                                                                                              ?></textarea>
 302                                  </td>
 303                          </tr>
 304  
 305  
 306                          <tr>
 307                                  <td>
 308                                          Copyright Status
 309                                  </td>
 310                                  <td>
 311                                          <select size=1  name="copyrightstatus">
 312                                                  <?php
 313                                                          $copystatus = $new_ps_file_info_array[ 'copyrightstatus' ];
 314                                                          if ( $copystatus == "Unknown" )
 315                                                          {
 316                                                                  echo "<option value=\"Unknown\" SELECTED >Unknown</option>\n";
 317                                                          }
 318                                                          else
 319                                                          {
 320                                                                  echo "<option value=\"Unknown\">Unknown</option>\n";
 321                                                          }
 322  
 323                                                          if ( $copystatus == "Copyrighted Work" )
 324                                                          {
 325                                                                  echo "<option value=\"Copyrighted Work\" SELECTED >Copyrighted Work</option>\n";
 326                                                          }
 327                                                          else
 328                                                          {
 329                                                                  echo "<option value=\"Copyrighted Work\">Copyrighted Work</option>\n";
 330                                                          }
 331  
 332                                                          if ( $copystatus == "Public Domain" )
 333                                                          {
 334                                                                  echo "<option value=\"Public Domain\" SELECTED >Public Domain</option>\n";
 335                                                          }
 336                                                          else
 337                                                          {
 338                                                                  echo "<option value=\"Public Domain\">Public Domain</option>\n";
 339                                                          }
 340                                                  ?>
 341                                          </select>
 342                                  </td>
 343                          </tr>
 344  
 345  
 346                          <tr>
 347                                  <td>
 348                                          Copyright Notice
 349                                  </td>
 350                                  <td>
 351                                          <textarea name="copyrightnotice" rows=3 cols=37 wrap="off"><?php echo $new_ps_file_info_array[ 'copyrightnotice' ]; ?></textarea>
 352                                  </td>
 353                          </tr>
 354  
 355  
 356                          <tr>
 357                                  <td>
 358                                          Copyright Info URL
 359                                  </td>
 360                                  <td>
 361                                          <?php
 362                                          echo "<input size=49 name=\"ownerurl\" type=\"text\" value=\"". $new_ps_file_info_array[ 'ownerurl' ] ."\">\n";
 363                                          if ($new_ps_file_info_array[ 'ownerurl' ] != "" )
 364                                          {
 365                                                  echo "<a href=\"". $new_ps_file_info_array[ 'ownerurl' ] ."\" > (". $new_ps_file_info_array[ 'ownerurl' ] .")</a>\n";
 366                                          }
 367                                          ?>
 368  
 369                                  </td>
 370                          </tr>
 371  
 372  
 373                          <tr>
 374                                  <td>
 375                                          Category
 376                                  </td>
 377                                  <td>
 378                                          <?php
 379                                          echo "<input size=49 name=\"category\" type=\"text\" value=\"". $new_ps_file_info_array[ 'category' ] ."\">\n";
 380                                          ?>
 381  
 382                                  </td>
 383                          </tr>
 384  
 385                          <tr>
 386                                  <td>
 387                                          Supplemental Categories
 388                                  </td>
 389                                  <td>
 390                                          <textarea name="supplementalcategories" rows=3 cols=37 wrap="off"><?php
 391                                                                                                  foreach( $new_ps_file_info_array[ 'supplementalcategories' ] as $supcat )
 392                                                                                                  {
 393                                                                                                          echo "$supcat&#xA;";
 394                                                                                                  }
 395                                                                                              ?>
 396                                          </textarea>
 397                                  </td>
 398                          </tr>
 399  
 400  
 401  
 402                          <tr>
 403                                  <td>
 404                                          Date Created
 405                                  </td>
 406                                  <td>
 407                                          <?php
 408                                                  echo "<input size=49 name=\"date\" type=\"text\" value=\"". $new_ps_file_info_array[ 'date' ] ."\">";
 409                                          ?>
 410                                          (Note date must be YYYY-MM-DD format)
 411                                  </td>
 412                          </tr>
 413  
 414                          <tr>
 415                                  <td>
 416                                          City
 417                                  </td>
 418                                  <td>
 419                                          <?php
 420                                                  echo "<input size=49 name=\"city\" type=\"text\" value=\"". $new_ps_file_info_array[ 'city' ] ."\">";
 421                                          ?>
 422                                  </td>
 423                          </tr>
 424  
 425  
 426                          <tr>
 427                                  <td>
 428                                          State
 429                                  </td>
 430                                  <td>
 431                                          <?php
 432                                                  echo "<input size=49 name=\"state\" type=\"text\" value=\"". $new_ps_file_info_array[ 'state' ] ."\">";
 433                                          ?>
 434                                  </td>
 435                          </tr>
 436  
 437  
 438                          <tr>
 439                                  <td>
 440                                          Country
 441                                  </td>
 442                                  <td>
 443                                          <?php
 444                                                  echo "<input size=49 name=\"country\" type=\"text\" value=\"". $new_ps_file_info_array[ 'country' ] ."\">";
 445                                          ?>
 446                                  </td>
 447                          </tr>
 448  
 449  
 450  
 451                          <tr>
 452                                  <td>
 453                                          Credit
 454                                  </td>
 455                                  <td>
 456                                          <?php
 457                                                  echo "<input size=49 name=\"credit\" type=\"text\" value=\"". $new_ps_file_info_array[ 'credit' ] ."\">";
 458                                          ?>
 459                                  </td>
 460                          </tr>
 461  
 462  
 463                          <tr>
 464                                  <td>
 465                                          Source
 466                                  </td>
 467                                  <td>
 468                                          <?php
 469                                                  echo "<input size=49 name=\"source\" type=\"text\" value=\"". $new_ps_file_info_array[ 'source' ] ."\">";
 470                                          ?>
 471                                  </td>
 472                          </tr>
 473  
 474  
 475  
 476                          <tr>
 477                                  <td>
 478                                          Headline
 479                                  </td>
 480                                  <td>
 481                                          <textarea name="headline" rows=3 cols=37 wrap="off"><?php echo $new_ps_file_info_array[ 'headline' ]; ?></textarea>
 482                                  </td>
 483                          </tr>
 484  
 485  
 486  
 487                          <tr>
 488                                  <td>
 489                                          Instructions
 490                                  </td>
 491                                  <td>
 492                                          <textarea name="instructions" rows=3 cols=37 wrap="off"><?php echo $new_ps_file_info_array[ 'instructions' ]; ?></textarea>
 493                                  </td>
 494                          </tr>
 495  
 496  
 497                          <tr>
 498                                  <td>
 499                                          Transmission Reference
 500                                  </td>
 501                                  <td>
 502                                          <textarea name="transmissionreference" rows=3 cols=37 wrap="off"><?php echo $new_ps_file_info_array[ 'transmissionreference' ]; ?></textarea>
 503                                  </td>
 504                          </tr>
 505  
 506                          <tr>
 507                                  <td>
 508                                          Job Name
 509                                  </td>
 510                                  <td>
 511                                          <?php
 512                                                  echo "<input size=49 name=\"jobname\" type=\"text\" value=\"". $new_ps_file_info_array[ 'jobname' ] ."\"> - Note: not used in Photoshop CS";
 513                                          ?>
 514                                  </td>
 515                          </tr>
 516  
 517                          <tr>
 518                                  <td>
 519                                          Urgency
 520                                  </td>
 521                                  <td>
 522                                          <select size="1" name="urgency">
 523                                                  <?php
 524                                                          for( $i = 1; $i <= 8; $i++ )
 525                                                          {
 526                                                                  echo "<option value=\"$i\"";
 527                                                                  if ( $new_ps_file_info_array[ 'urgency' ] == $i )
 528                                                                  {
 529                                                                          echo " SELECTED ";
 530                                                                  }
 531                                                                  echo ">";
 532                                                                  if ( $i == 1 )
 533                                                                  {
 534                                                                          echo "High";
 535                                                                  }
 536                                                                  else if ( $i == 5 )
 537                                                                  {
 538                                                                          echo "Normal";
 539                                                                  }
 540                                                                  else if ( $i == 8 )
 541                                                                  {
 542                                                                          echo "Low";
 543                                                                  }
 544                                                                  else
 545                                                                  {
 546                                                                          echo "$i";
 547                                                                  }
 548                                                                  echo "</option>\n";
 549                                                          }
 550                                                          if ( $new_ps_file_info_array[ 'urgency' ] == "none" )
 551                                                          {
 552                                                                  echo "<option value=\"none\" SELECTED >None</option>";
 553                                                          }
 554                                                          else
 555                                                          {
 556                                                                  echo "<option value=\"none\" >None</option>";
 557                                                          }
 558                                                   ?>
 559  
 560                                          </select>
 561                                  </td>
 562                          </tr>
 563  
 564                  </table>
 565                  <br>
 566                  <input type="submit" value="Update!">
 567  
 568  
 569          </form>
 570  
 571          <br>
 572          <br>
 573          <p>Powered by: <a href="http://www.ozhiker.com/electronics/pjmt/" >PHP JPEG Metadata Toolkit version <?php echo $GLOBALS['Toolkit_Version'] ?>, Copyright (C) 2004 Evan Hunter</a></p>     <!-- Change: displayed toolkit version numbers to reference Toolkit_Version.php - as of version 1.11 -->
 574          <br>
 575          <br>


[ Powered by PHPXref - Served by Debian GNU/Linux ]