Oh, here's the code im using
1.) Form data is received
2.) Data is inserted into database
3.) Retrieve record ID so we can name the new folder for the student after the records ID number
4.) Upload the file to a temporary holding place
5.) Unzip the file to proper location and delete the zip file from the holding place
6.) Log the event
7.) redirect user
Code: Select all
//=========================>
// Get the posted data
//=========================>
$SID = functions::strsafe($_POST['SID']);
$SSN = functions::strsafe($_POST['SSN']);
$student_name = functions::strsafe($_POST['student_name']);
$DOB = functions::strsafe($_POST['DOB']);
$parent_name = functions::strsafe($_POST['parent_name']);
$zip_code = functions::strsafe($_POST['zip_code']);
echo " $SID, $SSN, $student_name, $DOB, $parent_name, $zip_code <br>";
//================================================>
// Add new student information to the database
// then proceed to get the RID of the new student
//
// Once we have the RID we can upload the
// zipped file of images and then extract
// it to its proper location, and name it
// with the students RID
//================================================>
//======= Get Connection to DB ========>
$link = functions::getConnection();
//=====================================>
$query = "INSERT INTO `students` (`SID`, `student_name`, `SSN`, `DOB`, `zipCode`, `parent_name`)
VALUES ('$SID', '$student_name', '$SSN', '$DOB', '$zip_code', '$parent_name')";
$result = mysql_query($query);
if($result == FALSE){
echo "Error adding new student<br>";
}
else{
echo "Successfully created new student <br> Now uploading images...<br>";
}
//========= Close Link to DB ==========>
mysql_close($link);
//=====================================>
//======= Get Connection to DB ========>
$link = functions::getConnection();
//=====================================>
//==== Get the RID of the new student ====//
$query = "SELECT * FROM students WHERE SID = '$SID'";
$result = mysql_query($query);
if ($row_data = mysql_fetch_array($result))
{
$RID = $row_data['RID'];
echo "Retrieved RID: $RID <br>";
}
//========= Close Link to DB ==========>
mysql_close($link);
//=====================================>
//===== Move the file to its location =====//
$target = "received/".$RID.".zip";
echo "moving the uploaded file to $target <br>";
if(move_uploaded_file($_FILES['file_location']['tmp_name'], $target))
{
echo "The file has been uploaded <br>";
}
else {
echo "Sorry, there was a problem uploading your file. <br>";
}
//===== Unzip the file =====//
$archive = new PclZip($target);
if ($archive->extract(PCLZIP_OPT_PATH, "records/$RID") == 0) {
die("Error : ".$archive->errorInfo(true));
}
else{
//=== Delete the zip file ===//
unlink($target);
//================ Log the event ================//
//---- Get UID ----//
$UID = functions::getUID($_SESSION['username']);
functions::logEvent($UID, "added a new student, record # $RID");
//================= End Logging =================//
echo "<br><br>... <b>Fowarding you to the new student's profile </b><br>";
sleep(2);
//SEND USER TO THE STUDENTS RECORD//
echo <<<html
<script type="text/javascript">
<!--
window.location = "viewrecord.php?RID=$RID"
//-->
</script>
html;