[eluser]jvk22[/eluser]
I implemented a flash upload form in one of my controllers and whenever it runs it destroys all my sessions, but they seem to be re-stored after the controller done executing.
This is not all the code, but I think this is where the problem is occuring.
Code:
if(isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post' && !empty($_POST))
{
//restore session code begin. if you don't use session or cookie just ignor below code section.
if( isset($_POST['browser_cookie']) && $_POST['browser_cookie'] != "")
{
//retrive cookie from form field value. The EAFlashUpload sends the cookie as a value of form field due to Flash API limitations.
$cookie = split(";", $_POST['browser_cookie']);
foreach($cookie as $value)
{
$nvpair = split("=", $value);
$parsedcookie[trim($nvpair[0])] = $nvpair[1];
}
$_COOKIE = $parsedcookie;
session_start();
}
//restore session code end
//!!! If you don't use session or cookie then delete above code. !!!//
if ( !empty($_FILES) )
{
//existing folder on the server for files storing with write access
$uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/UploadedFiles/";
// define encoding for path names
$codepage = "ISO-8859-1";
//check file existence in the request
$file = $_FILES["Filedata"];
//check on upload errors
if ( $file['error'] != UPLOAD_ERR_OK )
{
switch( $file['error'] )
{
case UPLOAD_ERR_INI_SIZE:
echo "<eaferror>The uploaded file exceeds the upload_max_filesize directive in php.ini.</eaferror>";
break;
case UPLOAD_ERR_FORM_SIZE:
echo "<eaferror>Uploader didn't allow such file size</eaferror>";
break;
case UPLOAD_ERR_PARTIAL:
echo "<eaferror>Uploaded file hasn't been complete uploaded</eaferror>";
break;
case UPLOAD_ERR_NO_FILE:
echo "<eaferror>File hasn't been uploaded</eaferror>";
break;
}
return;
}
//Use this code if the existing files might be rewritten.
//$uploadfile = $uploaddir . mb_convert_encoding( basename($file['name']), $codepage , 'UTF-8' );
//define a full file path
if (extension_loaded('mbstring'))
$fileName = $uploaddir . mb_convert_encoding( basename($file['name']), $codepage , 'UTF-8' );
else if (extension_loaded('iconv'))
$fileName = $uploaddir . iconv("UTF-8", $codepage, basename($file['name']));
else
{
echo "<eaferror>Please enable mbstring extension or iconv extension in your php.ini file.</eaferror>";
}
// check on duplicate file names and if there is a file with the same name add "_(<counter>)" at the end of the name of the new file
$uniqueFileName = $fileName;
for($k = 1; $k < 50; $k++)
{
if(!file_exists($uniqueFileName))
{
break;
}
else
{
$pathInfo = pathinfo($fileName);
$uniqueFileName = sprintf("%s/%s_(%s).%s", $pathInfo['dirname'], $pathInfo['filename'], $k, $pathInfo['extension']);
}
}