Strict Standards Error while image upload with PHP script

后端 未结 2 1781
悲&欢浪女
悲&欢浪女 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);
    

提交回复
热议问题