<head>
<title>Admin upload</title>
</head>
<body>
<h1>Upload new files</h1>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<p>
Upload this file:<input type="file" name="userfile" maxlength="50">
<input type="submit" value="上传">
</p>
</form>
</body>
</html>
<head>
<title>资料上传Upload</title>
</head>
<body>
<h1>Uploading file</h1>
<?php
$files['userfile']['error']的结果将输出0,1,2,3,4,5. 其中0表示没有错误!
*/
if ($_FILES['userfile']['error']>0) {
echo 'Problem:';
switch ($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded max in phi.ini!';break;//1表示文件超过php配置里的大小限制
Case 2: echo 'File exceeded max_file_size';break;//2表示超过最大限制
case 3: echo 'File only partially uploaded';break;//3表示部分上传
case 4: echo 'No file upload'; break;//4表示没有上传
}
exit;
}
/*
如果文件类型非纯文本,输出提示 */
if ($_FILES['userfile']['type']!='text/plain') {
echo 'Problem:file is not plain text';
exit;
}
/*
转移文件路径,转移失败,输出错误
*/
$upfile='/uploads';//存储路径
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
if (!move_uploaded_file($_FILES['userfile']['tmp_name'],$upfile)) {
echo 'Problem could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem :possible file upload attack file:';
echo $_FILES['userfile']['name'];
exit;
}
echo 'File upload sucessfully<br/>';
//输出上传的文本的内容
$contents=file_get_contents($upfile);
file_put_contents($_FILES['userfile']['name'],$contents);
echo '<p>Preview of uploaded file contens:<br/></p>';
echo nl2br($contents);
echo '<br/><hr/>';
?>
</body>
</html>