4

I'm trying to make a image upload system to add meta-data to the files themselves.

I'm using the iptcembed from the GD library as shown below:

    <?php

// iptc_make_tag() function by Thies C. Arntzen
function iptc_make_tag($rec, $data, $value)
{
    $length = strlen($value);
    $retval = chr(0x1C) . chr($rec) . chr($data);

    if($length < 0x8000)
    {
        $retval .= chr($length >> 8) .  chr($length & 0xFF);
    }
    else
    {
        $retval .= chr(0x80) . 
                   chr(0x04) . 
                   chr(($length >> 24) & 0xFF) . 
                   chr(($length >> 16) & 0xFF) . 
                   chr(($length >> 8) & 0xFF) . 
                   chr($length & 0xFF);
    }

    return $retval . $value;
}

// Path to jpeg file
$path = './phplogo.jpg';

// We need to check if theres any IPTC data in the jpeg image. If there is then 
// bail out because we cannot embed any image that already has some IPTC data!
$image = getimagesize($path, $info);

if(isset($info['APP13']))
{
    die('Error: IPTC data found in source image, cannot continue');
}

// Set the IPTC tags
$iptc = array(
    '2#120' => 'Test image',
    '2#116' => 'Copyright 2008-2009, The PHP Group'
);

// Convert the IPTC tags into binary code
$data = '';

foreach($iptc as $tag => $string)
{
    $tag = substr($tag, 2);
    $data .= iptc_make_tag(2, $tag, $string);
}

// Embed the IPTC data
$content = iptcembed($data, $path);

// Write the new image data out to the file.
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
?>

However when I attach a form and change the $path to the path of the uploaded image and change the iptc array tags to variables form textfields in the data form, it doesn't put add the information.

The image will be uploaded but the tags for author, copyright are not there.

4

1 に答える 1

0

パーミッションの問題である場合、Web サーバー (ほとんどの場合 Apache または IIS) を実行しているユーザーが、格納されているディレクトリに書き込み可能である必要があります。

ファイルが確実に書き込まれるようにするには、格納されているディレクトリが誰でも書き込み可能である必要があります。セキュリティ上の問題になる可能性がありますが、いつでも変更を元に戻すことができます。

$path への FTP アクセスがあり (おそらく)、リモート ディレクトリのアクセス許可を変更できる場合は、$path ディレクトリのアクセス許可を "誰でも書き込み可能" または0777(3 つの 7 がそれぞれ所有者の書き込み許可を意味する 8 進数) に変更します。ファイル、所有者のグループ、およびその他のすべてのユーザー)。

Web サーバーがこれを実行できるユーザーの下で実行されている場合、次の手順で PHP 経由でディレクトリのアクセス許可を変更できます。

chmod(dirname($path),0777);

このdirname()関数は、指定されたパスを含むディレクトリを返します。

注意: 2 番目の引数の末尾の 0 は、0777 が 8 進数であることを意味します。777 と書くと 10 進数の 777 を意味し、8 進数の 777 は 10 進数の 511 です)。考えられる問題に関する追加情報については、chmod() のドキュメントを参照してください。

Web サーバーが実行されているユーザーを知りたい場合は、phpinfo()を使用できます。Web サーバーが Apache の場合、ユーザーとグループは、"User/group" の下の "apache2handler" セクションにあります。IIS およびその他のサーバーについては、見つけることができます (ただし、どのグループの下にあるかは正確にはわかりません)。

于 2011-05-10T20:46:32.390 に答える