php上传文件样例

一个php的上传例子,可以简单的实现文件上传

对于上传文件的大小,朋友建议修改配置的三处地方
配置文件在centos的路径:/etc/php.ini
大小限制如下,按需修改:
memory_limit = 128M
post_max_size = 30M
upload_max_filesize = 20M

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="zh-cn" />
<head>
</head>
<body>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <!--input value="30000" /-->
    <!-- Name of input element determines name in $_FILES array -->
    上传客户端swf:<input />
    <input value="上传" />
</form>
<!--这是处理上传的PHP程序upload.php-->
<?php
$uploaddir = '/var/www/html/bin/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
    echo "上传成功.\n";
}
else
{
    echo "上传失败!\n";
}
//================这是调试信息,可以不写=========
//echo 'Here is some more debugging info:';
//print_r($_FILES);
//============================================
print "</pre>";
?>
</body>
</html>
你可以留言,或者trackback 从你的网站

留言哦