Jump to content

How can I read an uploaded file (.csv) in Content page on Hanna code with PHP?


golfmk
 Share

Recommended Posts

From the Content page, where I have a simple web page I load a .csv file  where I have the data that I want to show later in a table.

What I need to know is how to load that .csv to use it in hanna code to create a tag type PHP, and show the table on the page that I mentioned later.

I hope you understand what I try to do. Thank you very much for your help.

 

Link to comment
Share on other sites

If you gave us some more background infos about the "big picture", I'm sure we could come up with more ideas.

e.g.

  • Is it always the same CSV you want to parse/display?
  • Does your client frequently upload CSVs (updates)?
  • Are you doing this in just one particular place, or in dozens of other areas / pages?
  • How big are those CSVs?

There's a great module (Handsontable) by @bernhard that you could use. The client could copy+paste from Excel to PW, and with little code you could display that as an HTML-table.

If it's data that don't need to be synced every day (with a cron job), you could do a one-time CSV-to-PW conversion (build a page that holds data/fields equivalent to the CSV data structure), and then let the client update this data inside PW.

re: speed / performance / caching etc.
If the server has to process a huge CSV every single time the page is requested, you could run into problems.

So... depending on your needs we might suggest going this route or another, and avoid to have bottlenecks, and probably making the UX for your client better.

re: Hanna Code
https://modules.processwire.com/modules/process-hanna-code/

 

 

  • Like 3
Link to comment
Share on other sites

3 hours ago, golfmk said:

What I need to know is how to load that .csv to use it in hanna code

In your Hanna code, the page that your Hanna tag exists on is accessible as $page. So if your CSV file is in a "single" file field named "csv_file" then you could get the file like this...

$csv_file = $page->csv_file;
if($csv_file) {
    // A file exists in the field, so make your table by parsing $csv_file 
}

 

  • Like 1
Link to comment
Share on other sites

14 hours ago, dragan said:

If you gave us some more background infos about the "big picture", I'm sure we could come up with more ideas.

e.g.

  • Is it always the same CSV you want to parse/display?
  • Does your client frequently upload CSVs (updates)?
  • Are you doing this in just one particular place, or in dozens of other areas / pages?
  • How big are those CSVs?

There's a great module (Handsontable) by @bernhard that you could use. The client could copy+paste from Excel to PW, and with little code you could display that as an HTML-table.

If it's data that don't need to be synced every day (with a cron job), you could do a one-time CSV-to-PW conversion (build a page that holds data/fields equivalent to the CSV data structure), and then let the client update this data inside PW.

re: speed / performance / caching etc.
If the server has to process a huge CSV every single time the page is requested, you could run into problems.

So... depending on your needs we might suggest going this route or another, and avoid to have bottlenecks, and probably making the UX for your client better.

re: Hanna Code
https://modules.processwire.com/modules/process-hanna-code/

 

 

I answer your questions here.

  • Yes, it's always the same.
  • The CSV I only upload once by me (in the page that I create, I have the option to upload a file, and that file is the CSV ), I show to the user the data in a table.
  • Yes, is only in one of my pages.
  • In the CVS I have like 5500 (in total) data.

I will try to solve it with your advices. So thank you very much for your time.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...