Imagecreatefromjpeg returns a black image after resize

后端 未结 2 1086
情深已故
情深已故 2021-01-27 15:49

I have a script to resize an uploaded image, but when I use it, it just returns a black square. All error messages are pointing at this function:

function resize         


        
2条回答
  •  悲&欢浪女
    2021-01-27 16:34

    According to Marc B's answer you could probably make a check if the file is a JPG file. (JPEG, JPG, jpg, jpeg extensions).

    it could be something like:

    $file = explode(".", $_POST['file']);
    $file_ext = $file[count($file)]; // Get the last thing in the array - in this way the filename can containg dots (.)
    $allowed_ext = array('jpg', 'JPG', 'jpeg', 'jpg');
    
    if( in_array($file_ext, $allowed_ext )
    {
        // The code for creating the image here.
    }
    

提交回复
热议问题