user2534454
user2534454

Reputation: 405

Error after upload the file

I have two files, 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!";

}


?>

And the second one 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>

When i try to upload the file i get an error and good answer. Error: Strict standards: Only variables should be passed by reference in D:\wamp\www\php_z\upload\upload.php on line 4

I'm a beginner in php but can someone explain me what to do to solve this problem wth errror?

Upvotes: 1

Views: 58

Answers (1)

castis
castis

Reputation: 8223

The function end() takes an array that can be passed by reference since it modifies the internal pointer of the array. What you've passed it is the return of explode(). Since the return of explode isn't necessarily a variable, it can't be passed by reference. What you should do is set a variable containing the return of explode(...) and then pass that to end().

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

Upvotes: 4

Related Questions