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

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

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?