¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

PHP/¥¯¥é¥¤¥¢¥ó¥È¦¤Î¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤òPHP¤Ç¼èÆÀ¤¹¤ëÊýË¡

Last-modified: 2018-11-14 (¿å) 15:23:56 (2153d)
Top / PHP / ¥¯¥é¥¤¥¢¥ó¥È¦¤Î¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤òPHP¤Ç¼èÆÀ¤¹¤ëÊýË¡

PHP

¥Ö¥é¥¦¥¶¤Ç¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¡¢PHP¤ËÅϤ¹ÊýË¡

¥Ö¥é¥¦¥¶Â¦¤Ç¼¡¤Î¤è¤¦¤Ëµ­Æþ¤¹¤ë¤È¡¢¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤òPHP¥×¥í¥°¥é¥à¤ËÅϤ¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

<html>
<body>
<form method="post" enctype="multipart/form-data" action="http://foo.jp/php/upload.php">
<input type="file" name="file0" value="">
<input type="submit" value="Á÷¿®">
</form>
</body>
</html>

PHP¦¤Ç¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò¼õ¤±¼è¤ëÊýË¡

PHP¦¤Ç¼¡¤Î¤è¤¦¤Ëµ­Æþ¤¹¤ë¤È¡¢¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò¼õ¤±¼è¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

<?php
$directory = './log/';

// ¥À¥¦¥ó¥í¡¼¥É ¥Õ¥¡¥¤¥ë
$downloadFile = "";
if (strlen($_GET['get']) > 0) {
    $downloadFile = $directory . $_GET['get'];
} else if (strlen($_POST['get']) > 0) {
    $downloadFile = $directory . $_POST['get'];
}

if (strlen($downloadFile) > 0) {
    // ************************************************************************
    // ¥Õ¥¡¥¤¥ë ¥À¥¦¥ó¥í¡¼¥É
    // ************************************************************************
    if (file_exists($downloadFile)) {
        $response = readFile($downloadFile);
        header("Content-type: application/octet-stream");
        //¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ëÁ÷¿®
        print($response);
        //¥Õ¥¡¥¤¥ëºï½ü
        unlink($downloadFile);
    } else {
        print("busy");
    }
} else {
    // ************************************************************************
    // ¥Õ¥¡¥¤¥ë ¥¢¥Ã¥×¥í¡¼¥É
    // ************************************************************************
    $uploadFile = $directory . $_FILES['file0']['name'];
    if (move_uploaded_file($_FILES['file0']['tmp_name'], $uploadFile)) {
        //À®¸ù
        print "OK";
    } else {
        //¼ºÇÔ
        print "NG";
    }
}

function readFile($filename)
{
    $ret = "";

    //¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ëÆɹþ
    if (!file_exists($filename))
    {
        $ret = ""; // "not found";
    } else {
        if (!($fp = fopen($filename, 'rb'))) exit;
        flock($fp, 2);
        $size = filesize($filename);
        $ret = fread($fp, $size);
        fclose($fp);
    }
    return $ret;
}
?>

PHP¦¤ËËÜÅö¤ËÅϤäƤ¤¤ë¤«¡¢³Îǧ¤¹¤ë¤¿¤á¤Î¥×¥í¥°¥é¥à(report.php)

PHP¦¤Ç¼õ¤±¼è¤ë¤¿¤á¤Ë¤Ï¡¢$_FILES¤Ë¥Õ¥¡¥¤¥ë»²¾ÈÍѤΥǡ¼¥¿¤¬Æþ¤Ã¤Æ¤¤¤ë¤³¤È¤¬½ÅÍפǤ¹¡£

<?php
    echo "<pre>";
    echo "_GET\n";
    print_r($_GET);

    echo "---\n";
    echo "_POST\n";
    print_r($_POST);

    echo "---\n";
    echo "_FILES\n";
    print_r($_FILES);

    echo "---\n";
    echo "php_errormsg\n";
    echo $php_errormsg;

    echo "---\n";
    echo "apache_request_headers\n";
    print_r(apache_request_headers());

    echo "</pre>";
?>

apache_request_headers()¤Ë¤Ä¤¤¤Æ

¥¯¥é¥¤¥¢¥ó¥È¤«¤éapache¤Ë¥ê¥¯¥¨¥¹¥È¤¹¤ë¥Ø¥Ã¥ÀÆâÍƤ¬¸«¤é¤ì¤Æ¡¢ÊØÍø¤Ç¤¹¡£¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤È¡¢¥³¥í¥ó¤Ç¶èÀڤäÆɽ¼¨¤Ç¤­¤Þ¤¹¡£

<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
    echo "$header: $value <br />\n";
}
?>

½ÐÎÏÎã

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, application/vnd.ms-powerpoint, */*
Accept-Encoding: gzip, deflate
Accept-Language: ja
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 212
Content-Type: multipart/form-data; boundary=---------------------------7d728e38b137e
Host: papuu.jp
UA-CPU: x86
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; (R1 1.5); .NET CLR 1.1.4322; .NET CLR 2.0.50727)

¥ê¥ó¥¯