0

I've looked at similar posts here but couldn't crack a solution. I'm getting the Strict Standards: Only variables should be passed by reference error here on the strtolower($file['name']))), line. Tried hours now looking for a solution but couldn't figure out how to correct. Can you highlight where I've gone wrong?

Note: Code Edited as per @Kolink's suggestion below:

<?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>";
}
?>
Darkzaelus
  • 2,059
  • 1
  • 15
  • 31
  • The problem isn't in your code shown. Show us the full stack trace. – Brad Aug 25 '13 at 15:35
  • possible duplicate of [Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference) – Lorenz Meyer Jun 21 '14 at 08:33

1 Answers1

2

end takes its argument by reference, since it modifies the original array by moving its internal pointer.

Since you appear to be using PHP 5.4, you can do this instead to get the last one:

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

That said, it's probably better to do it in several steps for readability:

$parts = explode(".",strtolower($file['name']));
$extension = $parts[count($parts)-1];
if( !in_array($extension,$allowedExtensions)) {
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • One more question, if I done use End, then im unable to print/echo all the files (images) uploading. I'm enabling multiple uploads here. I've edited my original code above – Konara mudiyanse Aug 25 '13 at 16:17