session_start(); include_once "include/form_process.php"; include_once "include/misc.php"; include_once "include/inout.php"; include_once "include/log.php"; include_once "include/class.AsiyaResults.php"; // Delete the browser cache MISCnocache(); $uploadresult=""; $uploadfilenameslist=""; $uploadtype = ""; /******************************************************************************/ /* check the posted data size */ $posteddata = INOUT_check_upload_size(); if ( $posteddata != "" ){ $uploadresult = $posteddata; } else{ /* check no session expiration */ if ( LOGcheck_session_expiration() ) { $uploadresult=DOCLEAR; } } $action = isset($_REQUEST["formaction"]) ? stripslashes($_REQUEST["formaction"]) : ""; //LOG // sets the testname $_SESSION[ASIYA]["testname"]=LOGtestname(); LOGaccess("ASIYA_UPLOAD", "\t$action"); /******************************************* UPLOAD FILES **/ if ( strcmp(DOUPLOAD,$action)==0 ){ $uploadtype = isset($_REQUEST["uploadtype"])? stripslashes($_REQUEST["uploadtype"]) : ""; $ar=(isset($_SESSION[ASIYA][$uploadtype]))? explode ( "#" , $_SESSION[ASIYA][$uploadtype] ) : array() ; if ( count($ar) >= 5 ){ $uploadresult = "WARN= Number of files exceed."; } else{ $result = doUpload ( "asiyafilename", $uploadtype ); // if correctly uploaded if ( strcmp( "UPLOADED" , substr( $result, 0, strlen("UPLOADED") )) == 0 ){ // delete the system if previously uploaded $uploadedfile = substr($result,strlen("UPLOADED=")); updateAsiyaSession($uploadtype, $uploadedfile); $uploadresult = "success"; } else { $uploadresult = $result; } } $uploadfilenameslist = $_SESSION[ASIYA][$uploadtype]; } if ( strcmp(DOREMOVE,$action)==0 ){ $uploadtype = isset($_REQUEST["uploadtype"])? stripslashes($_REQUEST["uploadtype"]) : ""; $uploadfilenameslist = doRemove ( $uploadtype ); $uploadresult = "success"; } function doRemove( $uploadtype ){ $artypes=array("sys","ref","src"); if (isset($_REQUEST["filetoremove"]) && in_array($uploadtype,$artypes) ){ $filetoremove=stripslashes($_REQUEST["filetoremove"]); #check that filetoremove is not present in the other arrays $itis = false; foreach ($artypes as $mytype ){ if ( $mytype !== $uploadtype ){ $ar=(isset($_SESSION[ASIYA][$mytype]))? explode ( "#" , $_SESSION[ASIYA][$mytype] ) : array() ; if ( in_array ( $filetoremove, $ar ) ){ $itis = true; } } } //if not present, then delete if ( !($itis)){ MISCdelete_files( $filetoremove, "data"); } //update asiya session $ar=(isset($_SESSION[ASIYA][$uploadtype]))? explode ( "#" , $_SESSION[ASIYA][$uploadtype] ) : array() ; foreach (array_keys($ar, $filetoremove) as $key) { unset($ar[$key]); } // save new system uploadedfile $_SESSION[ASIYA][$uploadtype] = join("#", $ar); return $_SESSION[ASIYA][$uploadtype]; } return ""; } /** upload the file inputfile according to the uploadtype */ function doUpload ( $inputfile , $uploadtype ){ $time = time(); // check if the folder exists INOUT_create_Asiya_data_location(); $result = MISCupload_file ( $inputfile, TESTPATH."/".LOGtestname()."/data/", LOGtestname() ); $time = MISC_elapsedtime($time); LOGaccess("ASIYAUPLOAD", "\telapsed time: $time; $uploadtype:$result"); return $result; } function updateAsiyaSession( $type, $uploadedfile ){ if ( $type === "src" ) { $_SESSION[ASIYA][$type] = $uploadedfile; } else{ if ( (isset($_SESSION[ASIYA][$type])) && (strlen($_SESSION[ASIYA][$type])>0) ){ $ar = split( "#", $_SESSION[ASIYA][$type] ); if ( in_array($uploadedfile, $ar ) ){ // does exist in the array #delete previous version foreach (array_keys($ar, $uploadedfile) as $key) { unset($ar[$key]); } } $ar[] = $uploadedfile; // save new system uploadedfile $_SESSION[ASIYA][$type] = join("#", $ar); } else{ $_SESSION[ASIYA][$type] = $uploadedfile; } } } ?>