golfmk Posted March 5, 2018 Share Posted March 5, 2018 Hello. I'm new using processwire and I would like to know how can I read an uploaded file (.csv) in the Content page on Hanna code with PHP? Thanks. Link to comment Share on other sites More sharing options...
DaveP Posted March 5, 2018 Share Posted March 5, 2018 Hi, and welcome. The answer to your question is 'Well, yes, probably.' Give us a bit more of an idea of what you are trying to do and we will try for a more detailed answer. 2 Link to comment Share on other sites More sharing options...
golfmk Posted March 5, 2018 Author Share Posted March 5, 2018 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 More sharing options...
elabx Posted March 5, 2018 Share Posted March 5, 2018 I think you need to concentrate on parsing the CSV file with a library like this one. Or also this function is built in PHP which takes a string as input: http://php.net/manual/en/function.str-getcsv.php 2 Link to comment Share on other sites More sharing options...
dragan Posted March 5, 2018 Share Posted March 5, 2018 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 Codehttps://modules.processwire.com/modules/process-hanna-code/ 3 Link to comment Share on other sites More sharing options...
Robin S Posted March 5, 2018 Share Posted March 5, 2018 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 } 1 Link to comment Share on other sites More sharing options...
golfmk Posted March 6, 2018 Author Share Posted March 6, 2018 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 Codehttps://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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now