This topic is locked

Import Only Page

12/5/2025 09:54:24
PHPRunner General questions
E
ecornwell author

Hello,

I have a "tools" site that we have setup like an add-on to some software we use internally. I was given a project to create a mass import from a CSV file that needs to geo-code an address to lat/long as part of its process. My thought was to use the import built in but I can't figure out how to make it work.

I'm looking for the following:

  • A page that has an import field and a few other custom fields for data. IE: Custom fields will be data that is set for all rows that doesn't need to be in the file but needs to be part of the upload. This will be set by the person uploading.
  • Once the file is uploaded and the fields set, a sort of a "Go" button to start the process.
  • 4 of the columns will contain 2 addresses (2 columns each merged together for the full address) that need to be looked up for lat/long each.
  • On the back end, the data will need to be validated and if successful, the data is added to the DB via Stored Procedures (I cannot do a direct insert as the data touches a few tables)
  • For each row, multiple stored-procs will need to be run with the result from the previous used for the next. (They return things like generated ID data, etc.)
  • I'd like the security to work the same as it does so I can just assign the needed users

I think I could get some of it through the events but I've struggled to get an inital page. I got just an upload only page but it didn't work well as it looks like it wants a list page. I'm not looking for someone to do this for me, just give me some tips on how to get started if it's possible.

Thank you!

ChatGPT 12/5/2025

Certainly! Setting up a mass import feature in PHPRunner with the specifications you described involves several steps. Here are some tips to help you get started:

1. Create a Custom Page for File Upload

  • Custom Page: Instead of using the built-in import feature, create a custom page in PHPRunner. Go to the "Pages" section and create a new page where you can include an upload field and additional custom fields.
  • File Upload: Add a file input to allow users to upload a CSV file. You can use HTML and PHP code for this. The file will need to be processed after upload.

2. Add Custom Fields

  • Custom Fields: Add additional fields to your page that will be used to collect data that is not included in the CSV. These fields can be added using standard form elements (e.g., input boxes or dropdowns).

3. Create a "Go" Button

  • Submit Button: Add a button that users will click to start the import process. This button can trigger a PHP function that handles the CSV processing and data validation.

4. Process the CSV File

  • Reading CSV: Use PHP's built-in functions (fgetcsv()) to read the uploaded CSV file line by line. For each row, you'll need to perform the following actions:
    • Extract the addresses from the specified columns.
    • Use a geocoding service (like Google Maps API) to convert addresses to latitude and longitude.



5. Validate Data

  • Data Validation: Implement validation checks for the data from the CSV and the additional fields before insertion. This could include checking for empty fields, correct formats, etc.

6. Call Stored Procedures

  • Database Interaction: Use PHP’s PDO or MySQLi to connect to your database and execute stored procedures for inserting data. You would need to prepare and execute statements for each row, passing in data as needed.
  • Sequential Execution: Since multiple stored procedures need to be run in sequence, ensure that you capture the output of one stored procedure to be used as input for the next.

7. Security and User Permissions

  • User Permissions: Use PHPRunner’s built-in security features to manage user permissions. Make sure the page you create is accessible only to users with the necessary rights to perform the import.
  • Session Management: Ensure that user sessions are properly managed so that only authorized users can initiate the import process.

8. Testing and Debugging

  • Test Your Implementation: Before going live, thoroughly test your implementation with various CSV files to ensure that all edge cases are handled, and data integrity is maintained.
  • Debugging: Use error handling to log errors or display messages for debugging purposes.

Example Code Snippet for CSV Upload Handling

Here’s a simple example of what your PHP code might look like for processing the uploaded CSV file:

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['csv_file'])) {
$file = $_FILES['csv_file']['tmp_name'];
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// Assume columns 0 and 1 are address parts
$address1 = $data[0] . ' ' . $data[1];
$address2 = $data[2] . ' ' . $data[3];

// Geocode addresses
$lat1 = geocode($address1);
$lat2 = geocode($address2);

// Validate data and call stored procedures
if (validData($data)) {
// Call your stored procedures here
}
}
fclose($handle);
}
}

function geocode($address) {
// Implement your geocoding logic here
}

function validData($data) {
// Implement your validation logic here
}

Conclusion

By breaking down the process into manageable steps and leveraging PHPRunner’s capabilities along with custom PHP code, you can create a robust mass import feature. Make sure to refer to the PHPRunner documentation for specifics about creating custom pages and managing database connections. Good luck with your project!