pwd
<code>
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import io
import cgitb
# デバッグ用(エラーをブラウザに表示)
cgitb.enable()
# 日本語対応
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding=’utf-8′)
# フルパス取得
script_path = os.path.abspath(__file__)
print(“Content-Type: text/html; charset=utf-8\n”)
print(“<html><head><title>フルパス表示</title></head><body>”)
print(“<h2>このCGIのフルパス:</h2>”)
print(f”<p>{script_path}</p>”)
print(“</body></html>”)
————————————–
per バージョン(pl)
#!/usr/bin/perl
use strict;
use warnings;
print “Content-Type: text/html; charset=utf-8\n\n”;
# フルパス取得
my $script_path = $ENV{‘SCRIPT_FILENAME’} || $ENV{‘PATH_TRANSLATED’} || ‘パス不明’;
print <<“HTML”;
<!DOCTYPE html>
<html>
<head><meta charset=”UTF-8″><title>フルパス確認</title></head>
<body>
<h2>このCGIのフルパス:</h2>
<p>$script_path</p>
</body>
</html>
ーーーーーーーーーーーーーーーーーーーーーーーー
PHPバージョン
<?php
// Content-Typeを明示
header(“Content-Type: text/html; charset=utf-8″);
// スクリプトのフルパス取得
$script_path = $_SERVER[‘SCRIPT_FILENAME’] ?? ‘不明’;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8”>
<title>PHPでフルパス確認</title>
</head>
<body>
<h2>このPHPファイルのフルパス:</h2>
<p><?php echo htmlspecialchars($script_path, ENT_QUOTES, ‘UTF-8’); ?></p>
</body>
</html>
</code>