ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS

PHP/ץ/File Uploader

Last-modified: 2010-05-16 () 05:53:06 (2744d)
Top / PHP / ץ / File Uploader

PHP/ץ

Ϥ

ե줿եϥƥݥեȤƥåץɤޤ
ΥƥݥեϽλ˺ޤΤǡ¸Ͻ񤭹߸¤ͭǥ쥯ȥ˥ԡޤ
ΤȤåץɤθե̾ϼǤΤǸե̾ǥԡǤޤ

ץ

񤭹߲ǽuploadǥ쥯ȥѰդΥե֤ޤ

uploader.html

<html>
<head><title>File Uploader</title></head>

<body>
<h1>File Uploader</h1>

<form method="post" enctype="multipart/form-data" action="uploader.php">
  <input type="file" name="upfile">
  <input type="submit" value="upload">
</form>

</body>
</html>

uploader.php

<html>
<head><title>File Uploader</title></head>

<body>
<h1>File Uploader</h1>

<?php
    define("UPLOAD_DIRECTORY", "./upload/");

    $fname = $_FILES['upfile']['name'];
    if (move_uploaded_file($_FILES['upfile']['tmp_name'], UPLOAD_DIRECTORY . $fname)) {
        chmod(UPLOAD_DIRECTORY . $fname, 0644);
        print("<b>" . $fname . "</b> uploaded!");
    } else {
        print("<b>" . $fname . "</b> upload failed ...<br />" . $_FILES['upfile']['error']);
    }
?>

</body>
</html>

Ϣ

php.iniΥե륢åץɴϢ

file_uploadsե륢åץɲ
upload_tmp_diråץѥƥݥǥ쥯ȥʻꤷʤȤϥƥǥեȤȤʤޤ
upload_max_filesizeåץɥեκ祵

ץ'upfile'ȤnameΥե᥿

$_FILES['upfile']['name']ºݤΥե̾
$_FILES['upfile']['tmp_name']ƥݥեȤƥåפƤȤΥե̾
$_FILES['upfile']['type']'image/jpeg'ȤäMIME
$_FILES['upfile']['size']եХȿ
$_FILES['upfile']['error']顼ɿ UPLOAD_ERR_OK(= 0)ʤ

顼ɿ

UPLOAD_ERR_OK0åץ
UPLOAD_ERR_INI_SIZE1åץɥե̤php.iniupload_max_filesizeͤĶƤ
UPLOAD_ERR_FORM_SIZE2åץɥե̤HTMLեǻꤷmax_file_sizeͤĶƤ<input type="hiddden" name="max_file_size" value="1000000">
UPLOAD_ERR_PARTIAL3åץɥեΰåץɤƤʤ
UPLOAD_ERR_NO_FILE4åץɼ