0

Below is the script that my ajax file uploader uses. The uploader itself works fine but i need a method of storing the files that are uploaded and I am using session variables. The problem is if I upload more than one file the first session variable is being overwritten each time i upload a file and so i end up with only $_SESSION['hamhamham'] containing data. Can someone tell me what i am doing wrong here? Thanks in advance

session_start();

$uploaddir = '../uploads/';
$uploadfile = $uploaddir . date() .time() . basename($_FILES['myfile']['name']);


/* $_SESSION['hamhamham'] = $uploadfile; */

$full = false;

if(isset($_SESSION['hamhamham'])){ 

    if(isset($_SESSION['hohoho'])){ 

        if(isset($_SESSION['workforme'])){ 

            if(isset($_SESSION['sweet'])){ 

                $full = true;

            }else{
                $_SESSION['sweet'] = $uploadfile;
            }

        }else{
            $_SESSION['workforme'] = $uploadfile;
        }

    }else{
        $_SESSION['hohoho'] = $uploadfile;
    }

}else{
    $_SESSION['hamhamham'] = $uploadfile;
}

if($full==false){
    if (move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile)) {
      echo "success";
    } else {
      // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
      // Otherwise onSubmit event will not be fired
      echo "error";
    }
}else{
    echo "too many files uploaded";
}

1 Answer 1

2

Make an array

$_SESSION['files'][] = $uploadFile;

To Access

foreach($_SESSION['files'] as $file_name)
{
    // do stuff
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mate! I owe you one virtual beer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.