English 中文(简体)
阅读文档元数据
原标题:Reading a File s Metadata

我正在为公共卫生和公共卫生科做一个包裹。

管理人能够进入上载页,然后上载并分类图像。 迄今情况良好。

The implementation will allow users to comment on the pictures the admin has uploaded, so I m implementing a database table to link comments with their respective images.

id | path .:. id | datetime | comment_title | comment_body | uid

迄今情况良好。

我想,管理人能够重新命名档案(不一定通过网站,而是通过FTP或其他渠道查阅),而不是打破整个系统。

因此,我正在考虑采用元数据系统,将国际发展法与图像联系起来。 这将使我免于上表,并允许对图像进行免费篡改(既把图像放在纸上,又改名为纸面上)。

问题是,我如何执行? 我怎么写一个附在档案上的元数据,我如何阅读? 谷歌在这方面没有取得任何实际成果。

如果能够做得更好,我也爱听!

感谢任何帮助。

最佳回答

虽然我没有使用XMPPHP关于电源的工具包,如你可能研究的内容:。 尽管如此,在一年多的时间里,它还是用甲型和n子更新。

XMP Toolkit PHP Extension is a PHP module which includes the Adobe XMP Toolkit SDK. This PHP5 extension will provide classes and methods to manipulate XMP Metadatas from files like jpegs, tiff, png, but also wav, mp3, avi, mpeg4, pdf, ai, eps… It’s based from the Adobe XMP Toolkit SDK 4.4.2. The goal of this extension is to have php classes which can open files, extract metadatas, manipulate them, and put them back within few lines of php code. This project is under GPL v3 License.

你们还可以把武断的元数据写到一个图像档案中。 如你在评论中所说,这只是用于初专组档案。

http://php.net/manual/en/Function.iptcembed.php

这里是获得和编制IPTC数据的一组评论的文字:

<?

    /************************************************************

        IPTC EASY 1.0 - IPTC data manipulator for JPEG images

        All reserved www.image-host-script.com

        Sep 15, 2008

    ************************************************************/

    DEFINE( IPTC_OBJECT_NAME ,  005 );
    DEFINE( IPTC_EDIT_STATUS ,  007 );
    DEFINE( IPTC_PRIORITY ,  010 );
    DEFINE( IPTC_CATEGORY ,  015 );
    DEFINE( IPTC_SUPPLEMENTAL_CATEGORY ,  020 );
    DEFINE( IPTC_FIXTURE_IDENTIFIER ,  022 );
    DEFINE( IPTC_KEYWORDS ,  025 );
    DEFINE( IPTC_RELEASE_DATE ,  030 );
    DEFINE( IPTC_RELEASE_TIME ,  035 );
    DEFINE( IPTC_SPECIAL_INSTRUCTIONS ,  040 );
    DEFINE( IPTC_REFERENCE_SERVICE ,  045 );
    DEFINE( IPTC_REFERENCE_DATE ,  047 );
    DEFINE( IPTC_REFERENCE_NUMBER ,  050 );
    DEFINE( IPTC_CREATED_DATE ,  055 );
    DEFINE( IPTC_CREATED_TIME ,  060 );
    DEFINE( IPTC_ORIGINATING_PROGRAM ,  065 );
    DEFINE( IPTC_PROGRAM_VERSION ,  070 );
    DEFINE( IPTC_OBJECT_CYCLE ,  075 );
    DEFINE( IPTC_BYLINE ,  080 );
    DEFINE( IPTC_BYLINE_TITLE ,  085 );
    DEFINE( IPTC_CITY ,  090 );
    DEFINE( IPTC_PROVINCE_STATE ,  095 );
    DEFINE( IPTC_COUNTRY_CODE ,  100 );
    DEFINE( IPTC_COUNTRY ,  101 );
    DEFINE( IPTC_ORIGINAL_TRANSMISSION_REFERENCE ,      103 );
    DEFINE( IPTC_HEADLINE ,  105 );
    DEFINE( IPTC_CREDIT ,  110 );
    DEFINE( IPTC_SOURCE ,  115 );
    DEFINE( IPTC_COPYRIGHT_STRING ,  116 );
    DEFINE( IPTC_CAPTION ,  120 );
    DEFINE( IPTC_LOCAL_CAPTION ,  121 );

    class iptc {
        var $meta=Array();
        var $hasmeta=false;
        var $file=false;


        function iptc($filename) {
            $size = getimagesize($filename,$info);
            $this->hasmeta = isset($info["APP13"]);
            if($this->hasmeta)
                $this->meta = iptcparse ($info["APP13"]);
            $this->file = $filename;
        }
        function set($tag, $data) {
            $this->meta ["2#$tag"]= Array( $data );
            $this->hasmeta=true;
        }
        function get($tag) {
            return isset($this->meta["2#$tag"]) ? $this->meta["2#$tag"][0] : false;
        }

        function dump() {
            print_r($this->meta);
        }
        function binary() {
            $iptc_new =   ;
            foreach (array_keys($this->meta) as $s) {
                $tag = str_replace("2#", "", $s);
                $iptc_new .= $this->iptc_maketag(2, $tag, $this->meta[$s][0]);
            }        
            return $iptc_new;    
        }
        function iptc_maketag($rec,$dat,$val) {
            $len = strlen($val);
            if ($len < 0x8000) {
                   return chr(0x1c).chr($rec).chr($dat).
                   chr($len >> 8).
                   chr($len & 0xff).
                   $val;
            } else {
                   return chr(0x1c).chr($rec).chr($dat).
                   chr(0x80).chr(0x04).
                   chr(($len >> 24) & 0xff).
                   chr(($len >> 16) & 0xff).
                   chr(($len >> 8 ) & 0xff).
                   chr(($len ) & 0xff).
                   $val;

            }
        }    
        function write() {
            if(!function_exists( iptcembed )) return false;
            $mode = 0;
            $content = iptcembed($this->binary(), $this->file, $mode);    
            $filename = $this->file;

            @unlink($filename); #delete if exists

            $fp = fopen($filename, "w");
            fwrite($fp, $content);
            fclose($fp);
        }    

        #requires GD library installed
        function removeAllTags() {
            $this->hasmeta=false;
            $this->meta=Array();
            $img = imagecreatefromstring(implode(file($this->file)));
            @unlink($this->file); #delete if exists
            imagejpeg($img,$this->file,100);
        }
    };


?>

例读版权体:

$i = new iptc("test.jpg");
echo $i->get(IPTC_COPYRIGHT_STRING); 

更新版权声明:

$i = new iptc("test.jpg");
echo $i->set(IPTC_COPYRIGHT_STRING,"Here goes the new data"); 
$i->write();
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签