modxcms / revolution

MODX Revolution - Content Management Framework
https://modx.com/
GNU General Public License v2.0
1.36k stars 528 forks source link

Updating to modx 3.0.3, cannot upload image, getting error, how to fix? #16372

Closed MoriorInvictus closed 1 year ago

MoriorInvictus commented 1 year ago

When i updated, i used fastUploadTv packets, when try to load, it doesn't work, shows me this

[2023-01-31 18:55:56] (ERROR @ /var/www/vhosts/siteurl.com/test1.siteurl.com/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 666) Could not load class: modPhpThumb from modphpthumb
[2023-01-31 18:55:56] (ERROR @ /var/www/vhosts/siteurl.com/test1.siteurl.com/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 1272) Problem getting service modphpthumb, instance of class modPhpThumb, from path /var/www/vhosts/siteurl.com/test1.siteurl.com/core/model/phpthumb/

When i tried default tv image, and make same, i upload image via file manager, and i get the error, the same, when i realod, image is uploaded, but when i try to show her on page, it just doesn't show up.

I Tried php from 7.4.13 to 8.1.14 Also i using fenom from pdoTools.

Tried with this system settings _phpthumb_allow_src_abovedocroot but result the same.

Also i updated from 2.8.4 to 3.0.0 then to 3.0.3

MoriorInvictus commented 1 year ago

also i updated file modPhpThumb from current repository, since in some issue have similar error, but they fixies doesn't fix mine

JoshuaLuckers commented 1 year ago

@MoriorInvictus this might be related to issue #16339. Can you try if this works for you? https://github.com/modxcms/revolution/issues/16339#issuecomment-1365508401

MoriorInvictus commented 1 year ago

No, i trying use phpThumb in plugin. And if i turn this plugin off, everything is work, how to use phpThumb in modx3 in plugin?

<?php
// set handler to OnFileManagerUpload

$fullPath = $source->getBases() ['pathAbsolute'] . $directory;
foreach ($files as $file)
{

    if (strripos($file['type'], 'image') === false || $file['type'] == 'image/svg+xml')
    {
        return;
    }

    $name = $file['name'];
    $pathToImage = $fullPath . $name;

    if (exif_imagetype($pathToImage) == IMAGETYPE_JPEG)
    {

        $params = array(
            'w' => 1920,
            'f' => 'jpeg',
            'q' => 90,
        );

    }
    elseif (exif_imagetype($pathToImage) == IMAGETYPE_PNG)
    {

        $params = array(
            'w' => 1920,
            'f' => 'png',
            'q' => 90,
        );

    }
    elseif (exif_imagetype($pathToImage) == IMAGETYPE_GIF)
    {
        return;
    }

    $phpThumb = $modx->getService('modphpthumb', 'modPhpThumb', MODX_CORE_PATH . 'src/Revolution/modPhpThumb.php', array());
    $phpThumb->setSourceFilename($pathToImage);

    foreach ($params as $k => $v)
    {
        $phpThumb->setParameter($k, $v);
    }

    if ($phpThumb->GenerateThumbnail())
    {
        if (!$phpThumb->renderToFile($pathToImage))
        {
            $modx->log(1, 'Error while uploading image [' . $pathToImage . ']');
        }
    }
    else
    {
        $modx->log(1, print_r($phpThumb->debugmessages, 1));
    }

}
JoshuaLuckers commented 1 year ago

@MoriorInvictus If you change the following line $phpThumb = $modx->getService('modphpthumb', 'modPhpThumb', MODX_CORE_PATH . 'src/Revolution/modPhpThumb.php', array()); into:

if (!$modx->services->has('phpthumb')) {
    $modx->services->add('phpthumb', new \MODX\Revolution\modPhpThumb($modx));
}

$phpThumb = $modx->services->get('phpthumb');

does that work?

MoriorInvictus commented 1 year ago

Thank you very much, you are magician, is there have instruction how to work with it? by your self, for example if i wanna transfer some plugins into new version?