0

This was a script that worked. Then I changed something (I really don't know what) and it no longer works. I start a session and then import a CSV file(s) which should get loaded into a table named with the filename. Here's how the code starts:

public function formProcess3(){
    $form_submission = false;
    $form_submission_type = '';
    $form_url = '';
    $upload_error = false;
    $upload_message = '';
    $import_error = false;
    $import_message = '';

    // Check if there was a form submission
    if(isset($_POST['type'])){

        if($_FILES['uploadedfile']['name']!==''){
            $form_submission = true;
            $form_submission_type = $_POST['type'];
            $form_url = $_POST['url'];
            if(strpos($_FILES['uploadedfile']['name'], '.csv') !== false){
                $upload_path = "data/";
                $upload_path = $upload_path . basename($_FILES['uploadedfile']['name']); 

                if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_path)) { }
                else { $upload_error = true; }

                $this->csvFiles = array($upload_path);
                //echo $this->csvFiles[0];
            } else {
                echo "Problem";
            }
        } else {
            $this->csvFiles = $merged['csvFiles'];
        }
    }

The commented code returns the correct path where the CSV file is stored. However, when I get to importing the CSV File, this is the code:

public function consumedImport(){

error_log('starting consumed import',0);

    $this->consumedPrep();
error_log('done consumed prep',0);

// Loop through each csvFile and create updated csv
foreach($_SESSION['csvFiles'] as $csvFile){

The problem is that now it is returning the error:

Notice: Undefined index: csvFiles in /dataimportprocess.php on line 164 Warning: Invalid argument supplied for foreach() in /dataimportprocess.php on line 164

Can anyone help? Please? I have tried isset, but it returns no data in the array. At the very top of the code, it does set certain variables and functions:

class Import {
private $dbConnection;
private $dbSelected;
public $csvFiles;
public $csvFilesUpdate;
John Conde
  • 217,595
  • 99
  • 455
  • 496
Red Knight 11
  • 127
  • 1
  • 10
  • 1
    The real problem is neither the notice nor the session-related functionality or lack thereof (which seems to be the root cause here) but that you are working with code you do not currently understand. It's hard for someone else to fix that for you. – Jon Dec 03 '13 at 15:58
  • Jon, I know that the error is caused because it doesn't see the data in the array. I know the file can be seen in an array, as I can echo the data from the array. You're right; I don't understand all the code. What I do know is that the line foreach($_SESSION['csvFiles'] as $csvFile){ should see the array executed by the line $this->csvFiles = array($upload_path); Is that not so? – Red Knight 11 Dec 03 '13 at 16:36

0 Answers0