上传文件后出错

时间:2015-01-05 22:09:28

标签: php

我有两个文件,upload.php:

<?php

$validExt=array("txt","xml");
$ext=end(explode(".", $_FILES['file']['name']));
if(($_FILES['file']['type']=='text/plain') ||($_FILES['file']['type']=='text/xml')&&($_FILES['file']['size']<1000)&& in_array($ext,$validExt)){
    if($_FILES['file']['error']>0){
        echo "ERROR!";
    }else{
        echo "Name: ".$_FILES['file']['name']."<br>";
        echo "Type: ".$_FILES['file']['type']."<br>";
        echo "Size: ".$_FILES['file']['size']."<br>";
        echo "Tmp name: ".$_FILES['file']['tmp_name']."<br>";
    }
}else{
    echo "wrong file!";

}


?>

第二个是index.html:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
</head>
<body>
    <form enctype="multipart/form-data" action="upload.php" method="post">
        <input name="file" type="file"/>
        <input type="submit" value="Wyslij" />
    </form>
</body>
</html>

当我尝试上传文件时,我收到错误和答案。 错误: 严格的标准:只有变量才能在第4行的D:\ wamp \ www \ php_z \ upload \ upload.php中通过引用传递

我是php的初学者,但是有人可以解释一下如何解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

函数end()采用一个可以通过引用传递的数组,因为它修改了数组的内部指针。你传递的是explode()的回归。由于爆炸的返回不一定是变量,因此不能通过引用传递。你应该做的是设置一个包含explode(...)返回的变量,然后将其传递给end()

$validExt = array("txt", "xml");
$ext = explode(".", $_FILES['file']['name']);
$ext = end($ext);