Giter Club home page Giter Club logo

Comments (1)

antonical avatar antonical commented on August 10, 2024

Working through this and adding some error handling seems to have resolved the issue. With the code below in public/legacy/modules/AOS_Products/AOS_Products.php and the vardef changed to image with the same properties as the user image. width, height etc. Ran a repair and rebuild from the admin section.

I can now add images to products! Eureka. Obviously this is a cludge and maybe I have got lucky. I cannot replace the site image though so maybe more of the same in that code. One step at a time.

No additional php errors show up in my Apache or php logs.

Here is my replacement code. I provide no guarantees or warranties and these changes will no doubt be overwritten in any upgrade!

public function save($check_notify = false)
{
    global $sugar_config, $mod_strings;

    if (isset($_POST['deleteAttachment']) && $_POST['deleteAttachment'] == '1') {
        $this->product_image = '';
    }

    require_once('include/upload_file.php');
    $GLOBALS['log']->debug('UPLOADING PRODUCT IMAGE');

    if (!empty($_FILES['uploadimage']['name'])) {
        $imageFileName = $_FILES['uploadimage']['name'] ?? '';
        if (!has_valid_image_extension('AOS_Products Uploaded image file: ' . $imageFileName, $imageFileName)) {
            LoggerManager::getLogger()->fatal("AOS_Products save - Invalid image file ext : '$imageFileName'.");
            throw new RuntimeException('Invalid request');
        }
    }

    if (!empty($_FILES['uploadimage']['tmp_name'])) {
        $uploadErrors = [
            UPLOAD_ERR_OK => 'There is no error, the file uploaded with success.',
            UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
            UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
            UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
            UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
            UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder. Introduced in PHP 5.0.3.',
            UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk. Introduced in PHP 5.1.0.',
            UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',
        ];

        $errorCode = $_FILES['uploadimage']['error'];

        if ($errorCode !== UPLOAD_ERR_OK) {
            die("Upload failed with error: $uploadErrors[$errorCode]");
        }

        if ($_FILES['uploadimage']['size'] > $sugar_config['upload_maxsize']) {
            die($mod_strings['LBL_IMAGE_UPLOAD_FAIL'] . $sugar_config['upload_maxsize']);
        }

        $prefix_image = $this->getGUID() . '_';
        $uploadDir = rtrim($sugar_config['upload_dir'], '/') . '/';
        $uploadedFilePath = $uploadDir . $prefix_image . $_FILES['uploadimage']['name'];
        
        if (move_uploaded_file($_FILES['uploadimage']['tmp_name'], $uploadedFilePath)) {
            $this->product_image = $sugar_config['site_url'] . '/' . $uploadDir . $prefix_image . $_FILES['uploadimage']['name'];
        } else {
            die("Failed to move uploaded file to destination.");
        }
    }

    require_once('modules/AOS_Products_Quotes/AOS_Utils.php');

    perform_aos_save($this);

    return parent::save($check_notify);
}

Maybe someone can take something from the above and fix the issue permanently. I have not looked at why I cannot change the site logo yet.

Tested with mulitple user accounts and works every time to both initially upload an image and also change it.

I hope this demonstrates I am willing to help in any way I can as we really want to start using SuiteCRM but cannot if basic functionality does not work!

I also still have many popups saying undefined or buttons saying undefined and have to guess the function!

Cheers
Tony

from suitecrm-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.