Strict Standards Error while image upload with PHP script

后端 未结 2 1752
悲&欢浪女
悲&欢浪女 2021-01-27 10:05

I try to write an image uploader with php. But it is giving an error when I try.

Error is:

Strict Standards: Only variables

相关标签:
2条回答
  • 2021-01-27 10:34

    Note $file_name_encrypted will not contain a real or matchable extension, because your appending the filename with md5:

    $file_name_encrypted = $file_name."".md5(rand(1, 1000000));

    e.g filename.jpg79054025255fb1a26e4bc422aef54eb4

    So it will never match any in your $allowedExts array. Fix that then:

    Change that line too:

    $extension = pathinfo($file_name_encrypted, PATHINFO_EXTENSION);
    

    Or explode then pass the exploded to the end() function.

    $temp = explode(".", $file_name_encrypted);
    $extension = end($temp);
    
    0 讨论(0)
  • 2021-01-27 10:40

    The way to fix this is to explode first then use that array in end. end() needs to get its parameter passed by reference because it manipulates internal pointer but if there is no variable reference it will not work correctly.
    Try this
    $array = explode(".", $file_name_encrypted);
    then
    $extension = end($array);

    0 讨论(0)
提交回复
热议问题