続:phpスライドショー
先日の続き。画像の属性定義用php。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>image attribute definition</title> </head> <body> <?php // 属性定義 $conf = './imgattr.conf'; $checkbox = $_REQUEST["CHK"]; $img = $_REQUEST['img']; $otherlines = array(); // 定義済み属性をまず取得 $fp = fopen( "$conf", "r" ); while(!feof($fp)){ $line = fgets($fp); $line = preg_replace("/\n/", "", $line ); $strs = preg_split("/\t/", $line); if ( $strs[0] ) { if ( $strs[0] == $img ) { $def[$strs[0]][$strs[1]]=1; } else { // その他の行を全部取得 array_push($otherlines, $line); } } } fclose($fp); // 新しく定義されたものを属性ファイルに追加 $fp=fopen($conf,"w"); flock($fp, LOCK_EX); if ( $checkbox ) { for ( $i=0; $i<sizeof($checkbox); $i++ ) { fputs ($fp, "$img\t${checkbox[$i]}\n"); $def[$img][$checkbox[$i]] = 1; } } foreach ( $otherlines as $otherline ) { fputs($fp, "$otherline\n" ); } flock($fp,LOCK_UN); fclose($fp); /////////// // default /////////// print ("FILE::" . $img . "<BR>\n"); print ('<A HREF="' . $img . '" TARGET="_BLANK"><IMG SRC="' . $img . '" HEIGHT=100></A><BR>'. "\n"); $def = array(); // 定義済み属性をまず取得 $fp = fopen( "$conf", "r" ); while(!feof($fp)){ $line = fgets($fp); $line = preg_replace("/\n/", "", $line ); $strs = preg_split("/\t/", $line); if ( $strs[0] ) { if ( $strs[0] == $img ) { $def[$strs[0]][$strs[1]]=1; } } } $attrlist = './img_attr.txt'; ?> <form name="defattr" method="post" action="./defattr.php"> <?php echo '<input type="hidden" name="img" value="'; echo $img; echo '"><BR>' . "\n"; $fp = fopen( "$attrlist", "r" ); $j = 0; echo "<TABLE>\n"; while(!feof($fp)){ $line = fgets($fp); $line = preg_replace("/\n/", "", $line ); if ( $line != "" ) { if ($j%4 == 0){ echo '<TR>'; } echo '<TD>'; if ( $def[$img][$line] ) { echo '<INPUT TYPE="CHECKBOX" CHECKED=1 name="CHK[]" VALUE="'; } else { echo '<INPUT TYPE="CHECKBOX" name="CHK[]" VALUE="'; } echo $line; echo '">'; //echo '<FONT SIZE=-2>'; echo '<A HREF="./viewer.php?attr='; echo "$line"; echo '" TARGET=_BLANK>'; echo "$line"; echo '</A>'; //echo '</FONT>'; echo '</TD>'; if ($j%4 == 3){ echo '</TR>'; } $j++; } } fclose($fp); echo "</TABLE>\n"; ?> <input type="submit" name="submit" value="define"> </form> </body> </html>