<?php
//start a PHP session.
class Upload {
//upload directory.
//make sure it exists
//chmod it to 0777 to be writable
var $upload_dir = "uploads/";
//the name of the file.
var $name = '';
//TMP name of the file on server.
var $tmp_name = '';
//the size of the file.
//this is measured in bytes
var $size = '';
//the mime type of the file.
//ex. image/png
var $type = '';
//number of files uploaded so far.
var $count = 1;
function Upload
($file = array()) {
//make sure that the file data is not empty.
//loop the file array
foreach ($file as $key => $val) {
$this -> {$key} = $val;
}
//execute the uploading method.
$this -> upload_file();
}
}
function upload_file() {
//make sure the the file has been uploaded
//make sure that the file can be moved to the "upload_dir"
//increment the file count.
$newcount = (!isset($_SESSION['filecount'])) ?
$this -> count : ($_SESSION['filecount'] + 1
);
$_SESSION['files'][$newcount]['filename'] = $this -> name;
$_SESSION['files'][$newcount]['filesize'] = $this -> size;
$_SESSION['files'][$newcount]['filetype'] = $this -> type;
} else {
//file could not be moved
return false;
}
} else {
//file was not uploaded
return false;
}
}
}
//get all the posted file data
$file = $_FILES['Filedata'];
//initialize the Upload class.
$upload = new Upload($file);
?>
<?php
//custom variable passed to the flash application
$customVariable = $_GET['customVariable'];
//the number of files uploaded
$totalFileCount = $_GET['totalFileCount'];
//loop the uploaded files.
//this is received from the flash application
for ($i = 0; $i < $totalFileCount; $i++) {
'filename' => $_GET['filename' . $i],
'filesize' => $_GET['filesize' . $i],
'filetype' => $_GET['filetype' . $i],
);
}
//appand some text to our data.
$data = "Custom Variable - " . $customVariable . "\n";
$data .= "Total File Count - " . $totalFileCount . "\n";
foreach ($files as $fKey => $fVal) {
foreach ($files[$fKey] as $fKey2 => $fVal2) {
$data .= $fKey2 . " no " . $fKey . " - " . $fVal2 . "\n";
}
}
//open a new log file.
$fh = fopen("uploads/test_" . time() . ".txt", "w");
//write the generated data to the file.
//close the log file handle
//response for the flash application
echo 'success';
?>