elboletaire / Watimage

:framed_picture: PHP image manipulation class
https://elboletaire.github.io/Watimage
Other
25 stars 17 forks source link

if the temporary file doesn't have an extension #2

Closed temaqueja closed 11 years ago

temaqueja commented 11 years ago

There is a problem with some hosting services or PHP versions that doesn't use filename extensions:

This is bad: Array ( [dirname] => /tmp [basename] => phpAp3r4W [filename] => phpAp3r4W ) => Array ( [0] => Can't get file extension of /tmp/phpAp3r4W )

This is ok: Array ( [dirname] => E:\easyphp13\binaries\tmp [basename] => phpC577.tmp [extension] => tmp [filename] => phpC577 )

Bypassing with an empty string as extension is working for my particular case:

private function getFileExtension( &$file )
{
    $f = pathinfo($file);
    if ( empty($f['extension']) )
        return '';   // <-- BYPASS
        //throw new Exception("Can't get file extension of $file");

    return $f['extension'];
}
elboletaire commented 11 years ago

The method "getFileExtension" is used only when using the "setImage" method (or when setting an image with the construct method). So, if you are having this problem is because you are trying to treat the temporary file instead of a "real" file.

This class was not intended to be used this way. You should first save the file in your server and then treat the image:

if (move_uploaded_file($_FILES['whatever']['tmp_name'], 'your_real_destination.ext'))
{
    // Now you can / should use watimage with the resulting image file (your_real_destination.ext)
    $watimage = new Watimage('your_real_destination.ext');
    $watimage->whatever();
}

Instead of...

$watimage = new Watimage($_FILES['whatever']['tmp_name']);
$watimage->whatever();

Which is what you were doing, if I'm not wrong.