I though this looked like a bit of fun - I had a go. I started at the tutorial below but the PHP is a little wrong - well it is for my PHP setup.
http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001591.html
I added some logging to my PHP so that I could see what it was doing too. This is my PHP (in very TEST mode). I will be making lots of improvements. I will also create a C# one for any .NET apps that might require something like this. I might even port the actionscript up to AS 3.0
<?php
logIt(’Started upload.php’);
function logIt($message = ‘message’) {
$handle = fopen(’log.txt’, ‘a’);
fwrite($handle, “$message\n”);
fclose($handle);
}
$MAXIMUM_FILESIZE = 1024 * 999999;
$MAXIMUM_FILE_COUNT = 100; // keep maximum 10 files on server
logIt(’Max filesize:’ . $MAXIMUM_FILESIZE);
//echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
logIt(’Current file size’ . $_FILES['Filedata']['size']);
move_uploaded_file($_FILES['Filedata']['tmp_name'], “./tmp/”.$_FILES['Filedata']['name']);
//$type = exif_imagetype(”./temporary/”.$_FILES['Filedata']['name']);
$type = 1;
if ($type == 1 || $type == 2 || $type == 3) {
@rename(”./tmp/”.$_FILES['Filedata']['name'], “./images/”.$_FILES['Filedata']['name']);
logIt(’Renaming to: ‘ . “./images/”.$_FILES['Filedata']['name']);
} else {
unlink(”./tmp/”.$_FILES['Filedata']['name']);
logIt(’Deleting temp file.’);
}
}
$directory = opendir(’./images/’);
logIt(’Directory handle: ‘ . var_dump($directory));
$files = array();
while ($file = readdir($directory)) {
if(!is_dir($file)){
array_push($files, array(’./images/’.$file, filectime(’./images/’.$file)));
logIt(’Adding to file list array: ‘ . $file);
}
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) - $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b) {
if ($a[1] == $b[1]) {
return 0;
} else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
logIt(”Ended upload.php\n—————————–\n”);
?>