Custom Export Report issue in Magento 2CSV import not working - Need AssistanceExport report not showing fieldsIssue with custom reportCustom csv export - customersMagento 2 add custom columns in exportCannot export list of customer from the grid magento 2Magento Customer Grid Custom attribute can't export csv and export xmlHow to change “input file” storage location in customer account edit formMagento 2.3 email attachment not working while sending custom emailMagento 2 Custom sales report export issue

Secure my password from unsafe servers

Is TA-ing worth the opportunity cost?

Why are the inside diameters of some pipe larger than the stated size?

Why use regularization instead of decreasing the model

Is it true that control+alt+delete only became a thing because IBM would not build Bill Gates a computer with a task manager button?

What are these mathematical groups in U.S. universities?

Does the Voyager team use a wrapper (Fortran(77?) to Python) to transmit current commands?

WordCloud: do not eliminate duplicates

Where is the rule for moving slowly when searching for traps that’s referenced by Dungeon Delver?

Why can I log in to my Facebook account with a misspelled email/password?

Casting Goblin Matron with Plague Engineer on the battlefield

Unexpected route on a flight from USA to Europe

Traveling from Germany to other countries by train?

Ampacity of Conductive Tape

Validation and verification of mathematical models

In the movie Harry Potter and the Order or the Phoenix, why didn't Mr. Filch succeed to open the Room of Requirement if it's what he needed?

Why should public servants be apolitical?

How do I change the output voltage of the LM7805?

French equivalent of "Make leaps and bounds"

Why is there a need to prevent a racist, sexist, or otherwise bigoted vendor from discriminating who they sell to?

Is there a loss of quality when converting RGB to HEX?

Is Odin inconsistent about the powers of Mjolnir?

Is this cheap "air conditioner" able to cool a room?

Does this smartphone photo show Mars just below the Sun?



Custom Export Report issue in Magento 2


CSV import not working - Need AssistanceExport report not showing fieldsIssue with custom reportCustom csv export - customersMagento 2 add custom columns in exportCannot export list of customer from the grid magento 2Magento Customer Grid Custom attribute can't export csv and export xmlHow to change “input file” storage location in customer account edit formMagento 2.3 email attachment not working while sending custom emailMagento 2 Custom sales report export issue






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I need to export the custom grid to the csv file. I have used the below code in my listing.xml file.



<exportButton class="MagentoUiComponentExportButton">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="options" xsi:type="array">
<item name="cvs" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">catalogreport/export/gridToCsv</item>
</item>
<item name="xml" xsi:type="array">
<item name="value" xsi:type="string">xml</item>
<item name="label" xsi:type="string" translate="true">Excel XML</item>
<item name="url" xsi:type="string">catalogreport/export/gridToXml</item>
</item>
</item>
</item>
</argument>
</exportButton>


Then in my




Module/Controller/Adminhtml/Export/gridToCsv.php




class GridToCsv extends Action


public function execute()

$fileName = "CustomSales_". date('Ymd_His').".csv";
$dataSource = //The data fetches here;
$handle = fopen($fileName, 'w');
// Adding my logic to write the content to the file
$this->downloadCsv($fileName);




public function downloadCsv($fileName)

if (file_exists($fileName))
//set appropriate headers
header('Content-Description: File Transfer');
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename='.basename($fileName));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileName));
ob_clean();flush();
readfile($fileName);





This is working fine, The file is downloading successfully, But here my question is the CSV file is storing into the root directory, I need to change to pub/media/import directory.



How this can be done here? I want to store the csv file inside pub/media/import directory.



Can anyone suggest me please. Thanks!!










share|improve this question
































    1















    I need to export the custom grid to the csv file. I have used the below code in my listing.xml file.



    <exportButton class="MagentoUiComponentExportButton">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="options" xsi:type="array">
    <item name="cvs" xsi:type="array">
    <item name="value" xsi:type="string">csv</item>
    <item name="label" xsi:type="string" translate="true">CSV</item>
    <item name="url" xsi:type="string">catalogreport/export/gridToCsv</item>
    </item>
    <item name="xml" xsi:type="array">
    <item name="value" xsi:type="string">xml</item>
    <item name="label" xsi:type="string" translate="true">Excel XML</item>
    <item name="url" xsi:type="string">catalogreport/export/gridToXml</item>
    </item>
    </item>
    </item>
    </argument>
    </exportButton>


    Then in my




    Module/Controller/Adminhtml/Export/gridToCsv.php




    class GridToCsv extends Action


    public function execute()

    $fileName = "CustomSales_". date('Ymd_His').".csv";
    $dataSource = //The data fetches here;
    $handle = fopen($fileName, 'w');
    // Adding my logic to write the content to the file
    $this->downloadCsv($fileName);




    public function downloadCsv($fileName)

    if (file_exists($fileName))
    //set appropriate headers
    header('Content-Description: File Transfer');
    header('Content-Type: application/csv');
    header('Content-Disposition: attachment; filename='.basename($fileName));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($fileName));
    ob_clean();flush();
    readfile($fileName);





    This is working fine, The file is downloading successfully, But here my question is the CSV file is storing into the root directory, I need to change to pub/media/import directory.



    How this can be done here? I want to store the csv file inside pub/media/import directory.



    Can anyone suggest me please. Thanks!!










    share|improve this question




























      1












      1








      1








      I need to export the custom grid to the csv file. I have used the below code in my listing.xml file.



      <exportButton class="MagentoUiComponentExportButton">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="options" xsi:type="array">
      <item name="cvs" xsi:type="array">
      <item name="value" xsi:type="string">csv</item>
      <item name="label" xsi:type="string" translate="true">CSV</item>
      <item name="url" xsi:type="string">catalogreport/export/gridToCsv</item>
      </item>
      <item name="xml" xsi:type="array">
      <item name="value" xsi:type="string">xml</item>
      <item name="label" xsi:type="string" translate="true">Excel XML</item>
      <item name="url" xsi:type="string">catalogreport/export/gridToXml</item>
      </item>
      </item>
      </item>
      </argument>
      </exportButton>


      Then in my




      Module/Controller/Adminhtml/Export/gridToCsv.php




      class GridToCsv extends Action


      public function execute()

      $fileName = "CustomSales_". date('Ymd_His').".csv";
      $dataSource = //The data fetches here;
      $handle = fopen($fileName, 'w');
      // Adding my logic to write the content to the file
      $this->downloadCsv($fileName);




      public function downloadCsv($fileName)

      if (file_exists($fileName))
      //set appropriate headers
      header('Content-Description: File Transfer');
      header('Content-Type: application/csv');
      header('Content-Disposition: attachment; filename='.basename($fileName));
      header('Expires: 0');
      header('Cache-Control: must-revalidate');
      header('Pragma: public');
      header('Content-Length: ' . filesize($fileName));
      ob_clean();flush();
      readfile($fileName);





      This is working fine, The file is downloading successfully, But here my question is the CSV file is storing into the root directory, I need to change to pub/media/import directory.



      How this can be done here? I want to store the csv file inside pub/media/import directory.



      Can anyone suggest me please. Thanks!!










      share|improve this question
















      I need to export the custom grid to the csv file. I have used the below code in my listing.xml file.



      <exportButton class="MagentoUiComponentExportButton">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="options" xsi:type="array">
      <item name="cvs" xsi:type="array">
      <item name="value" xsi:type="string">csv</item>
      <item name="label" xsi:type="string" translate="true">CSV</item>
      <item name="url" xsi:type="string">catalogreport/export/gridToCsv</item>
      </item>
      <item name="xml" xsi:type="array">
      <item name="value" xsi:type="string">xml</item>
      <item name="label" xsi:type="string" translate="true">Excel XML</item>
      <item name="url" xsi:type="string">catalogreport/export/gridToXml</item>
      </item>
      </item>
      </item>
      </argument>
      </exportButton>


      Then in my




      Module/Controller/Adminhtml/Export/gridToCsv.php




      class GridToCsv extends Action


      public function execute()

      $fileName = "CustomSales_". date('Ymd_His').".csv";
      $dataSource = //The data fetches here;
      $handle = fopen($fileName, 'w');
      // Adding my logic to write the content to the file
      $this->downloadCsv($fileName);




      public function downloadCsv($fileName)

      if (file_exists($fileName))
      //set appropriate headers
      header('Content-Description: File Transfer');
      header('Content-Type: application/csv');
      header('Content-Disposition: attachment; filename='.basename($fileName));
      header('Expires: 0');
      header('Cache-Control: must-revalidate');
      header('Pragma: public');
      header('Content-Length: ' . filesize($fileName));
      ob_clean();flush();
      readfile($fileName);





      This is working fine, The file is downloading successfully, But here my question is the CSV file is storing into the root directory, I need to change to pub/media/import directory.



      How this can be done here? I want to store the csv file inside pub/media/import directory.



      Can anyone suggest me please. Thanks!!







      magento2 grid csv export






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 29 at 11:05







      Manjunath

















      asked Jul 29 at 10:20









      ManjunathManjunath

      797 bronze badges




      797 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          1














          Try changing Content-Disposition in function downloadCsv($fileName)to



          header('Content-Disposition: attachment; filename='.$directory.'/'.$fileName);


          Where $directory will be the media folder path which you can get dynamically by adding dependency in constructor using below code



          use MagentoFrameworkAppFilesystemDirectoryList;

          protected $_filesystem;

          public function __construct(
          MagentoFrameworkFilesystem $filesystem
          )

          $this->_filesystem = $filesystem;



          $mediapath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
          $directory = mediapath.'import'





          share|improve this answer



























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283649%2fcustom-export-report-issue-in-magento-2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Try changing Content-Disposition in function downloadCsv($fileName)to



            header('Content-Disposition: attachment; filename='.$directory.'/'.$fileName);


            Where $directory will be the media folder path which you can get dynamically by adding dependency in constructor using below code



            use MagentoFrameworkAppFilesystemDirectoryList;

            protected $_filesystem;

            public function __construct(
            MagentoFrameworkFilesystem $filesystem
            )

            $this->_filesystem = $filesystem;



            $mediapath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
            $directory = mediapath.'import'





            share|improve this answer





























              1














              Try changing Content-Disposition in function downloadCsv($fileName)to



              header('Content-Disposition: attachment; filename='.$directory.'/'.$fileName);


              Where $directory will be the media folder path which you can get dynamically by adding dependency in constructor using below code



              use MagentoFrameworkAppFilesystemDirectoryList;

              protected $_filesystem;

              public function __construct(
              MagentoFrameworkFilesystem $filesystem
              )

              $this->_filesystem = $filesystem;



              $mediapath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
              $directory = mediapath.'import'





              share|improve this answer



























                1












                1








                1







                Try changing Content-Disposition in function downloadCsv($fileName)to



                header('Content-Disposition: attachment; filename='.$directory.'/'.$fileName);


                Where $directory will be the media folder path which you can get dynamically by adding dependency in constructor using below code



                use MagentoFrameworkAppFilesystemDirectoryList;

                protected $_filesystem;

                public function __construct(
                MagentoFrameworkFilesystem $filesystem
                )

                $this->_filesystem = $filesystem;



                $mediapath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
                $directory = mediapath.'import'





                share|improve this answer













                Try changing Content-Disposition in function downloadCsv($fileName)to



                header('Content-Disposition: attachment; filename='.$directory.'/'.$fileName);


                Where $directory will be the media folder path which you can get dynamically by adding dependency in constructor using below code



                use MagentoFrameworkAppFilesystemDirectoryList;

                protected $_filesystem;

                public function __construct(
                MagentoFrameworkFilesystem $filesystem
                )

                $this->_filesystem = $filesystem;



                $mediapath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
                $directory = mediapath.'import'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 29 at 12:32









                Prachi SaxenaPrachi Saxena

                3281 silver badge8 bronze badges




                3281 silver badge8 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283649%2fcustom-export-report-issue-in-magento-2%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form