0

我在这里看过类似的帖子,但无法破解解决方案。我得到了 Strict Standards: Only variables should be pass by reference error here 就strtolower($file['name']))),行了。现在尝试了几个小时寻找解决方案,但无法弄清楚如何纠正。你能强调我哪里出错了吗?

注意:根据@Kolink 的建议编辑代码如下:

<?php
require_once 'upload_config.php';

$mydirectory = myUploadDir();

$uploaded_file_counter = 0;
$UploadLimit = $_POST['counter'];

for ($i = 0; $i <= $UploadLimit; $i++) {
    $file_tag = 'filename' . $i;
    $filename = $_FILES[$file_tag]['name'];

    if ($filename != null) {
        $rand = time();
        $str = "$rand$filename";

        // set folder name in here.
        $filedir = myUploadDir();

        //change the string format.
        $string = $filedir . $str;

        $patterns[0] = "/ /";
        $patterns[1] = "/ /";
        $patterns[1] = "/ /";

        $replacements[1] = "_";

        $dirname = strtolower(preg_replace($patterns, $replacements, $string));
        //end of changing string format

        //checking the permitted file types
        if ($check_file_extentions) {
            $allowedExtensions = allowedfiles();

            foreach ($_FILES as $file) {
                if ($file['tmp_name'] > '') {
                    /*if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) */
                    if (!in_array(array_reverse(explode(".", strtolower($file['name'])))[0], $allowedExtensions)) {
                        $fileUploadPermission = 0;
                    } else {
                        $fileUploadPermission = 1;
                    }
                }
            }
        } else {
            $fileUploadPermission = 1;
        }

        //end of checking the permitted file types
        if ($fileUploadPermission) {
            if (move_uploaded_file($_FILES[$file_tag]['tmp_name'], $dirname)) {
                echo "<p>"; ?>
                <div><?php echo "<img style='height:100px;width:200px' src='$dirname'>"; ?></div> <?php
                echo "</p>";

                $uploaded_file_counter += 1;
            }
        }
    }
}

if ($uploaded_file_counter == 0) {
    echo "<br /> <b style='font-weight:bold;color:red'>Opss! Please select an image file<b>";
} else {
    echo "<br /> <b>You request " . $i . " image files to upload and " . $uploaded_file_counter . " files uploaded sucessfully</b>";
}
?>
4

1 回答 1

2

end通过引用获取其参数,因为它通过移动其内部指针来修改原始数组。

由于您似乎使用的是 PHP 5.4,因此您可以这样做来获取最后一个:

if( !in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))

也就是说,为了便于阅读,最好分几个步骤来完成:

$parts = explode(".",strtolower($file['name']));
$extension = $parts[count($parts)-1];
if( !in_array($extension,$allowedExtensions)) {
于 2013-08-25T15:35:19.747 回答