0

Direct use of $_FILES Superglobal detected.

I have Used for get image file in backend.

 protected function getTmpFileName()
{
    $tmpName = null;
    if (isset($_FILES['groups'])) {
        $tmpName = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
    } else {
        $tmpName = is_array($this->getValue()) ? $this->getValue()['tmp_name'] : null;
    }
    return $tmpName;
}
9
  • Why and where you use?
    – Sohel Rana
    Commented May 7, 2019 at 6:54
  • where and then you see this error ? Commented May 7, 2019 at 6:55
  • this is error , because use superglobal like ( $_POST, $_GET,$_FILES etc.) isn`t good practice! Commented May 7, 2019 at 6:56
  • you try get image of the product ? Commented May 7, 2019 at 6:58
  • yes, which image you want to get? from where ? Commented May 7, 2019 at 7:00

2 Answers 2

1

If you are using $_FILES in magento 2 code anywhere that will give you error because PHP $_FILES tag that doesn’t support directly so you need to use that magento 2 own code.

do something like this :

$uploader = $this->_objectManager->create('Magento\MediaStorage\Model\File\Uploader',['fileId' => 'file_name']);

 // print_r($uploader->validateFile());

                                   //$ffgko = $_FILES['file_name']['name'];

                                   $fInam = $uploader->validateFile();

                                   $ffgko = $fInam['name'];

using of object manger is not good practice too, but you can use it for testing, and after replace it with decency injection

or check here : Create beautiful image upload in configuration magento 2

and here you can check good detail explanation how to do that! : https://www.magevision.com/blog/post/add-image-upload-in-configuration-magento-2/

0

I hope you are trying to use a custom backend model for image upload on system.xml, then you can try this

class Image extends \Magento\Config\Model\Config\Backend\Image{

    protected function getTmpFileName(){

        //$path = 'sectionId/groupId/fieldId' from system.xml
        return $this->_requestData->getTmpName($path);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.