Skip to main content
deleted 4 characters in body
Source Link
simple guy
  • 2.5k
  • 8
  • 32
  • 59

I have an input file form in phtml to import data from csv file type like this:

<div class="import-shipping">
  <div class="header">
    <h4>CSV File:</h4>
  </div>
  <form class="import-shipping-form" action="<?= $postUrl ?>" method="POST" enctype="multipart/form-data">
    <?php echo $block->getBlockHtml('formkey'); ?>
    <input type="file" required class="required-entry" name="csv" />
    <button type="submit">Import</button>
  </form>
</div>

How can i read the validate the the csv file and turn it into an array, and validate the file input asfile type is csv in my controller?

for example my csv file look like this:

csv file example

I have an input file form in phtml to import data from csv file type like this:

<div class="import-shipping">
  <div class="header">
    <h4>CSV File:</h4>
  </div>
  <form class="import-shipping-form" action="<?= $postUrl ?>" method="POST" enctype="multipart/form-data">
    <?php echo $block->getBlockHtml('formkey'); ?>
    <input type="file" required class="required-entry" name="csv" />
    <button type="submit">Import</button>
  </form>
</div>

How can i read the validate the csv file and turn it into an array, and validate the file input as is csv in my controller?

for example my csv file look like this:

csv file example

I have an input file form in phtml to import data from csv file type like this:

<div class="import-shipping">
  <div class="header">
    <h4>CSV File:</h4>
  </div>
  <form class="import-shipping-form" action="<?= $postUrl ?>" method="POST" enctype="multipart/form-data">
    <?php echo $block->getBlockHtml('formkey'); ?>
    <input type="file" required class="required-entry" name="csv" />
    <button type="submit">Import</button>
  </form>
</div>

How can i read the csv file and turn it into an array, and validate the file input file type is csv in my controller?

for example my csv file look like this:

csv file example

Tweeted twitter.com/StackMagento/status/938002419157557249
Source Link
simple guy
  • 2.5k
  • 8
  • 32
  • 59

Read input csv file and convert it to array

I have an input file form in phtml to import data from csv file type like this:

<div class="import-shipping">
  <div class="header">
    <h4>CSV File:</h4>
  </div>
  <form class="import-shipping-form" action="<?= $postUrl ?>" method="POST" enctype="multipart/form-data">
    <?php echo $block->getBlockHtml('formkey'); ?>
    <input type="file" required class="required-entry" name="csv" />
    <button type="submit">Import</button>
  </form>
</div>

How can i read the validate the csv file and turn it into an array, and validate the file input as is csv in my controller?

for example my csv file look like this:

csv file example