帮帮忙看,一般的小问题

<html>
<head>Uploading...</head>
<body>
 <h1>Uploading file...</h1>

<?php

if($_FILES['userfile']['error'] >0)
{
echo 'Problem:';
switch ($_FILES['userfile']['error'])
{
case 1:echo 'File exceeded upload_max_filesize';break;
case 2:echo 'File exceeded max_file_size';break;
case 3:echo 'File only partially uploaded';break;
case 4:echo 'No File uploaded';break;
case 6:echo 'Cannot upload file:No temp directory specified';break;
case 7:echo 'Upload failed: Cannot write to disk';break;
}
exit;
}

if($_FILES['userfile']['type'] != 'text/plain')
{
echo 'Problem: file is not plain text';
exit;
}
$upfile = '/uploads/'.$_FILES['userfile']['name'];

if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
if(!move_uploaded_file($_FILES['userfile']['tmp_name'],$upfile))
{
echo 'Problen: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problen:Possible file upload attack.Filename:';
echo $_FILES['userfile']['name'];
exit;
}

echo 'File uploaded successfully<br><br>';

$contents = file_get_contents($upfile);
$contents = strip_tags($contents);
file_put_contents($_FILES['userfile']['name'],$contents);

echo '<p>Preview of uploaded file contents:<br /><hr/>';
echo nl2br($contents);
echo '<br/><hr/>';
?>
</body>
</html>
运行情况是:
Uploading...
Uploading file...
Problem: file is not plain text,不懂,好像是move_upload_file,好像也有什么问题啊,帮忙看看

作者: nickwill1984   发布时间: 2011-06-03

PHP code
if($_FILES['userfile']['type'] != 'text/plain') {
    echo 'Problem: file is not plain text';
    exit;  //执行到这里强制结束脚本运行了,说明前面的代码木有问题,而是你选择上传的文件不是文本文件
}

作者: T5500   发布时间: 2011-06-03

if($_FILES['userfile']['type'] != 'text/plain')
{
echo 'Problem: file is not plain text';
exit;
}

这个,只能接受txt呢

作者: snmr_com   发布时间: 2011-06-03